C# Program to search for a string in an array of strings

karthikeya Boyini
Published on 14-Sep-2018 13:06:38
Use Linq Contains() method to search for as specific string in an array of strings.string[] arr = { "Bag", "Pen", "Pencil"};Now, add the string in a string variable i.e. the string you want to search.string str = "Pen";Use the Contains() method to search the above string.arr.AsQueryable().Contains(str);Let us see the entire ... Read More

C# Linq Contains Method

Chandu yadav
Published on 14-Sep-2018 13:04:25
To check for an element in a string, use the Contains() method.The following is our string array.string[] arr = { "Java", "C++", "Python"};Now, use Contains() method to find a specific string in the string array.arr.AsQueryable().Contains(str);Let us see the complete example.Example Live Demousing System; using System.Linq; using System.Collections.Generic; class Demo {   ... Read More

C# Cast method

Samual Sam
Published on 14-Sep-2018 13:02:55
To cast elements, use the Cast() method.The following is our list.List<object> myList = new List<object> { "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<string> res = myList.AsQueryable().Cast<string>().Select(str => str.Substring(0, 2));Let us see ... Read More

C# Average Method

George John
Published on 14-Sep-2018 13:00:08
To find the average of integers in C#, use the Queryable Average() method.Let’s say the following is our integer array.var arr = new int[] { 10, 17, 25, 30, 40, 55, 60, 70 };Now, use the Average() method to get the average of the elements.double avg = Queryable.Average(arr.AsQueryable());Example Live Demousing System; ... Read More

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

karthikeya Boyini
Published on 14-Sep-2018 12:59:47
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

Implicit conversion from Byte to Decimal in C#

Ankith Reddy
Published on 14-Sep-2018 12:56:25
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# Program to convert a Double to an Integer Value

Samual Sam
Published on 14-Sep-2018 12:56:03
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# Any Method

Arjun Thakur
Published on 14-Sep-2018 12:52:00
The Any method checks whether any of the element in a sequence satisfy a specific condition or not.If any element satisfy the condition, true is returned.Let us see an example.int[] arr = {5, 7, 10, 12, 15, 18, 20};Now, using Any() method, we will check whether any of the element ... Read More

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

karthikeya Boyini
Published on 14-Sep-2018 12:51:29
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

C# Program to convert a Byte value to an Int32 value

Chandu yadav
Published on 14-Sep-2018 12:48:38
To convert a Byte value to an Int32 value, use the Convert.ToInt32() method.Int32 represents a 32-bit signed integer.Let’s say the following is our Byte value.byte val = Byte.MaxValue;;Now to convert it to Int32.int intVal = Convert.ToInt32(val);Let us see the complete example.Example Live Demousing System; public class Demo {    public static ... Read More
Advertisements