Karthikeya Boyini has Published 2193 Articles

C# OverflowException

karthikeya Boyini

karthikeya Boyini

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

959 Views

OverflowException is thrown when the parameter value is out of integer ranges.Let us see an example.When we set a value to int.Parse() method that is out of integer range, then OverflowException is thrown as shown below −Example Live Demousing System; class Demo {    static void Main() {       ... Read More

C# Program to convert a Double value to an Int64 value

karthikeya Boyini

karthikeya Boyini

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

2K+ Views

To convert a Double value to an Int64 value, use the Convert.ToInt64() method.Int64 represents a 64-bit signed integer.Let’s say the following is our double value.double val = 23.951213e12;Now to convert it to Int64.long longVal = Convert.ToInt64(val);Let us see the complete example.Example Live Demousing System; public class Demo {    public static ... Read More

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

karthikeya Boyini

karthikeya Boyini

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

818 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

229 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

311 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

10K+ 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

3K+ 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

133 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

930 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

2K+ 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

Advertisements