Tuple Rest Property in C#

Samual Sam
Published on 14-Sep-2018 14:56:18
Create tuples of eight or more elements by nesting tuple objects in the Rest property.The tuple would look like −Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>Above, the 8th element is added using Rest property.Let us see an example.Example Live Demousing System; public class Program {    public static void Main() ... Read More

C# Program to access tuple elements

Ankith Reddy
Published on 14-Sep-2018 14:53:03
Create a tuple.var myTuple = Tuple.Create(1, 2.5M, "Amit", "100");Now to access tuple elements, use the properties.To access first element.myTuple.Item1To access second element.myTuple.Item2In the same way, for other elements, use the properties as shown below −Example Live Demousing System; public class Program {    public static void Main() {       ... Read More

Understanding IndexOutOfRangeException Exception in C#

karthikeya Boyini
Published on 14-Sep-2018 14:52:52
It occurs when Index is outside the bounds of the array.Let us see an example. We have declare an array with 5 elements and set the size as 5.int[] arr = new int[5]; arr[0] = 10; arr[1] = 20; arr[2] = 30; arr[3] = 40; arr[4] = 50;Now, we try ... Read More

C# Program to return specified number of elements from the beginning of a sequence

Arjun Thakur
Published on 14-Sep-2018 14:49:36
Set an array and arrange it in descending order using OrderByDescending.int[] prod = { 290, 340, 129, 540, 456, 898, 765, 789, 345};Now, use the Take() method to return specified number of elements from the beginning.Enumerable<int> units = prod.AsQueryable().OrderByDescending(s => s).Take(2);Let us see the complete code.Example Live Demousing System; using System.Linq; ... Read More

Understanding Array IndexOutofBoundsException in C#

Samual Sam
Published on 14-Sep-2018 14:49:24
Array IndexOutofBoundsException occurs in Java. The equivalent of it in C# is IndexOutOfRangeException.The IndexOutOfRangeException occurs when Index is outside the bounds of the array.Example Live Demousing System; using System.IO; using System.Collections.Generic; namespace Demo {    class Program {       static void Main(string[] args) {          int[] ... Read More

C# Enum Format Method

Chandu yadav
Published on 14-Sep-2018 14:44:23
The Format method converts value of a specified enumerated type to its equivalent string representation. Here you can also set the format i.e. d for Decimal, x for HexaDecimal, etc.We have the following enumeration.enum Stock { PenDrive, Keyboard, Speakers };The default value gets assigned (initialize).PenDrive = 0 Keyboard = 1 ... Read More

Convert.ToUInt32 Method in C#

karthikeya Boyini
Published on 14-Sep-2018 14:44:01
Convert a specified value to a 32-bit unsigned integer using the Convert.ToUInt32 method.The following is our string.string str = "210";Now, let us convert it to a 32-bit unsigned integer.uint res; res = Convert.ToUInt32(str);Example Live Demousing System; public class Demo {    public static void Main() {       string str ... Read More

C# Enum Equals Method

George John
Published on 14-Sep-2018 14:40:40
To find the equality between enums, use the Equals() method.Let’s say we have the following Enum.enum Products { HardDrive, PenDrive, Keyboard};Create two Products objects and assign the same values.Products prod1 = Products.HardDrive; Products prod2 = Products.HardDrive;Now check for equality using Equals() method. It would be True since both have the ... Read More

C# Enum CompareTo Method

Samual Sam
Published on 14-Sep-2018 14:40:10
Compare two enums using the CompareTo() method in C#.The method returns any of the following value −Less than zero: Value of source is less than value of targetZero: Value of source is equal to the value of targetMore than zero: Value of source is more than value of targetExample Live Demousing ... Read More

C# Linq Last() Method

karthikeya Boyini
Published on 14-Sep-2018 14:36:56
Get the last element from a sequence using the Linq Last() method.The following is our array.int[] val = { 10, 20, 30, 40 };Now, get the last element.val.AsQueryable().Last();Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo {    static void Main() {       int[] val = { 10, ... Read More
Advertisements