Ankith Reddy has Published 1070 Articles

C# Program to access tuple elements

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 09:09:46

257 Views

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

C# Math.BigMul Method

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 09:07:03

142 Views

Use the Math.BigMul() method to find the product of two 32-bit numbers.The following are our two numbers.int one = 345272828; int two = 887685744;Now, get the product.long res; res = Math.BigMul(one, two);Example Live Demousing System; using System.Globalization; class Demo {    static void Main() {       int one = ... Read More

Convert.ToUInt64 Method in C#

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 09:03:26

140 Views

Use the Convert.ToUInt64() method to convert a specified value to a 64-bit unsigned integer.The following is our char.char ch = 'a';Now, let’s convert it to a 64-bit unsigned integer.ulong res; res = Convert.ToUInt64(ch);Here is the complete example.Example Live Demousing System; public class Demo {    public static void Main() {   ... Read More

C# Program to find a key in Dictionary

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 09:02:10

203 Views

Firstly, set a Dictionary collection with elements.Dictionary d = new Dictionary() {    {1, "Applianes"},    {2, "Clothing"},    {3, "Toys"},    {4, "Footwear"},    {5, "Accessories"} };Now, let’s say you need to check whether key 5 exists or not. For that, use ContainsKey() method. It returns True if key ... Read More

Get Upperbound and Lowerbound of a three-dimensional array in C#

Ankith Reddy

Ankith Reddy

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

1K+ Views

To get the Upperbound and Lowerbound, use the GetUpperBound() GetLowerBound() methods in C#, respectively.The parameter to be set under these methods is the dimensions i.e.Let’s say our 3D array is −int[, , ] arr = new int[2, 3, 4];For a three-dimensional arrays, dimension 0.arr.GetUpperBound(0) arr.GetLowerBound(0)For a three-dimensional arrays, dimension 1.arr.GetUpperBound(1) ... Read More

Implicit conversion from Byte to Decimal in C#

Ankith Reddy

Ankith Reddy

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

282 Views

Byte represents an 8-bit unsigned integer.Implicit conversion of an 8-bit unsigned integer (Byte) to a Decimal is possible. Let us see how.Here’s our Byte value.byte val = 16;To implicitly convert, just assign the value as shown below −decimal dec; dec = val;Let us see the complete example.Example Live Demousing System; public ... Read More

C# Linq ThenBy Method

Ankith Reddy

Ankith Reddy

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

247 Views

Orders elements in a sequence using ThenBy() method.We have the following string array.string[] str = { "AAA", "AAAA", "A", "AAAAA", "AAAAAAAAA" };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 = str.AsQueryable() .OrderBy(alp => ... Read More

Get bounds of a C# three-dimensional array

Ankith Reddy

Ankith Reddy

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

347 Views

To get the bounds of a three-dimensional array, use the GetUpperBound() GetLowerBound() methods in C#.The parameter to be set under these methods is the dimensions i.e.Let’s say our array is −int[, , ] arr = new int[3, 4, 5];For a three-dimensional arrays, dimension 0.arr.GetUpperBound(0) arr.GetLowerBound(0)For a three-dimensional arrays, dimension 1.arr.GetUpperBound(1) ... Read More

C# Program to return the difference between two sequences

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 08:34:54

180 Views

Set two sequences.double[] arr1 = { 10.2, 15.6, 23.3, 30.5, 50.2 }; double[] arr2 = { 15.6, 30.5, 50.2 };To get the difference between both the above arrays, use Except() method.IEnumerable res = arr1.AsQueryable().Except(arr2);The following is the complete code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; class Demo {    static ... Read More

C# Program to return the only element that satisfies a condition

Ankith Reddy

Ankith Reddy

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

276 Views

The Single() method returns the only element that satisfies a condition. If more than one such element is visible, then an error is thrown.The following is our string array.string[] str = { "jack", "tom", "henry", "time"};Now, use the Single() method to get each element. Then, we have used Lambda Expression ... Read More

Advertisements