Samual Sam has Published 2492 Articles

C# Program to convert an Int32 value to a decimal

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:48:26

2K+ Views

To convert an Int32 value to a decimal, use the Convert.ToDecimal() method.Int32 represents a 32-bit signed integer.Let’s say the following is our Int32 value.int val = 2923;Now to convert it to decimal.decimal decVal = Convert.ToDecimal(val);Let us see the complete example.Example Live Demousing System; public class Demo {    public static void ... Read More

C# Program to convert a Double to an Integer Value

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:45:01

15K+ Views

To convert a Double value to an integer value, use the Convert.ToInt32() method.Int32 represents a 32-bit signed integer.Let’s say the following is our double value.double val = 21.34;Now to convert it to Int32.int res = Convert.ToInt32(val);Let us see the complete example.Example Live Demousing System; public class Demo {    public static ... Read More

C# Cast method

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:43:19

1K+ Views

To cast elements, use the Cast() method.The following is our list.List myList = new List { "Mac", "Windows", "Linux", "Solaris" };Now, cast and use the Cast() method with substring() method to display the first two letters of every string in the list.IEnumerable res = myList.AsQueryable().Cast().Select(str => str.Substring(0, 2));Let us see ... Read More

C# Program to order array elements in descending order

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:41:43

156 Views

To orders elements in a sequence in descending order, use ThenBy() and OrderByDescending.This is our string array.string[] myStr = { "Keyboard", "Laptop", "Mouse", "Monitor" };Now, use OrderByDescending to order element in Descending order. Inside that calculate the length of each string and use Lambda Expressions as well.IEnumerable res = myStr.AsQueryable().OrderByDescending(ch ... Read More

C# Linq Zip Method

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:39:48

1K+ Views

Merge sequences using predicate with Zip method.Here are our arrays to be merged.int[] intArray = { 10, 20, 30, 40 }; string[] stringArray = { "Jack", "Tim", "Henry", "Tom" };Now let’s use the Zip method to merge both the arrays.intArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two)The following ... Read More

C# Linq SkipLast Method

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:36:50

2K+ Views

Skip elements from the end and return the remaining elements using the SkipLast() method.The following is an array.int[] marks = { 45, 88, 50, 90, 95, 85 };Now, let us skip two elements from the end using SkipLast() and Lambda Expressions, but this is done after arranging the elements in ... Read More

C# Linq Sum() Method

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:32:57

9K+ Views

Find the sum of elements using the Linq Sum() method.Here’s our list with integer elements.List list = new List { 99, 34, 77, 75, 87, 35, 88};Now find the sum using the Sum() method.list.AsQueryable().Sum();The following is an example to find the sum of elements of a list with integer elements.Example Live ... Read More

C# Linq TakeWhile() Method

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:31:13

498 Views

Get elements as long as the condition is true in a sequence using the TakeWhile() method.The following is our list with strings.IList str = new List(){ "Car", "Bus", "Truck", "Airplane"};Now, let’s say we need the strings whose length is less than 4. For that, use Lambda Expressions and add it ... Read More

LinkedList AddLast method in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:29:12

301 Views

Declare a string array.string [] students = {"Jenifer", "Angelina", "Vera"};Add it to a LinkedList.string [] students = {"Jenifer", "Angelina", "Vera"};Now, use AddLast() method to add a node at the end.list.AddLast("Anne");Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       string [] students = {"Jenifer", ... Read More

C# SingleorDefault() Method

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:26:22

3K+ Views

The method returns a single specific element of a sequence. If the element is not present in the sequence, then the default value is returned.We have two string arrays here.string[] str1 = { "one" }; string[] str2 = { };First array is checked for a single element, whereas the second ... Read More

Advertisements