Karthikeya Boyini has Published 2383 Articles

Implicit conversion from 32-bit unsigned integer (UInt) to Decimal in C#

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:44:10

702 Views

Implicit conversion of a 32-bit unsigned integer (UInt) to a Decimal requires you to first declare a UInt.uint val = 342741539;Now to convert it to decimal, just assign the value.decimal dec; // implicit dec = val;Example Live Demousing System; public class Demo {    public static void Main() {     ... Read More

C# Queryable Union Method

karthikeya Boyini

karthikeya Boyini

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

139 Views

Perform Union on two sequences using the Queryable Union method.The following are our arrays.int[] arr1 = { 29, 40, 15, 55, 70, 30, 90 }; int[] arr2 = { 30, 36, 40, 18, 15, 55, 75 };Now, get the Union of the arrays using the Union method.arr1.AsQueryable().Union(arr2);Example Live Demousing System; using ... Read More

Get the width and height of a three-dimensional array

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:37:18

207 Views

Let’s say our three-dimensional array is −int[, , ] arr = new int[3, 4, 5];To get the height and width i.e. the rows and columns.Array.GetLength(0) – for rows Array.GetLength(1) – for columnsExample Live Demousing System; class Program {    static void Main() {       int[, , ] arr = ... Read More

C# Enum TryParse() Method

karthikeya Boyini

karthikeya Boyini

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

8K+ Views

The TryParse() method converts the string representation of one or more enumerated constants to an equivalent enumerated object.Firstly, set an enum.enum Vehicle { Bus = 2, Truck = 4, Car = 10 };Now, let us declare a string array and set some values.string[] VehicleList = { "2", "3", "4", "bus", ... Read More

C# Queryable Take() Method

karthikeya Boyini

karthikeya Boyini

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

2K+ Views

Get specified number of elements from the beginning using the Take() method.The following is our array.int[] marks = { 35, 72, 50, 90, 95, 85, 52, 67 };Now, use OrderByDescending to order the elements in Descending order. Then use the Take() method to get the elements.marks.AsQueryable().OrderByDescending(s => s).Take(5);Let us see ... Read More

C# Program to order array elements

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:30:42

82 Views

Use ThenBy() method to order array elements. Let’s say we have the following string array.string[] str = { "Sandler", "Jack", "Tom", "Matt", "Henry", "Johnny" };Now, use Lambda Expressions and set a condition inside the ThenBy() method to sort the strings according to the number of characters they have.IEnumerable res = ... Read More

C# Linq SelectMany Method

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:30:14

691 Views

Use SelectMany method to collapse elements into a single collection like an error.An example would be to convert string to character array. The following is our string array.string[] str = { "Mobile", "Laptop", "Tablet" };Now, convert to character array.str.SelectMany(item => item.ToCharArray());Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo ... Read More

C# Single() Method

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:27:09

1K+ Views

Get only a single element of a sequence using the Single() method.Let’s say we have a string array with only one element.string[] str = { "one" };Now, get the element.str.AsQueryable().Single();Here is our code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {   ... Read More

Removing whitespaces using C# Regex

karthikeya Boyini

karthikeya Boyini

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

1K+ Views

Let’s say we want to remove whitespace from the following string str1.string str1 = "Brad Pitt";Now, use Regex Replace to replace whitespace with empty. Here, we have used System.Text.RegularExpressions.string str2 = System.Text.RegularExpressions.Regex.Replace(str1, @"\s+", "");Let us see the complete example.Example Live Demousing System; using System.Text.RegularExpressions; namespace Demo {    class Program { ... Read More

C# Orderby Descending

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:23:07

306 Views

Use Orderby descending in C# to sort elements in descending order.The following is our list −IList emp = new List() { new Employee() { EmployeeRank = 3, EmpName = "Tom", EmpMarks = 90 } , new Employee() { EmployeeRank = 4, EmpName = "Katie", EmpMarks = 95 } };Now to ... Read More

Advertisements