Chandu yadav has Published 1163 Articles

C# Linq Contains Method

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 08:58:04

2K+ Views

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

Represent Int64 as a Hexadecimal String in C#

Chandu yadav

Chandu yadav

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

1K+ Views

To represent Int64 as a Binary string in C#, use the ToString() method and set the base as the ToString() method’s second parameter i.e.16 for Hexadecimal.Int64 represents a 64-bit signed integer.Firstly, set an Int64 variable.long val = 947645;Now, convert it to a hex string by including 16 as the second ... Read More

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

Chandu yadav

Chandu yadav

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

7K+ Views

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

C# Linq LastorDefault Method

Chandu yadav

Chandu yadav

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

2K+ Views

Use the LastorDefault() method to return the last element of a sequence or a default value if element isn’t there.The following is our empty list.List val = new List { };Now the following will not be able to display the last element since the list is empty. Therefore, the default ... Read More

C# Queryable TakeLast() Method

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 08:31:38

1K+ Views

Get specified number of elements from the end using the TakeLast() method.The following is our array.int[] pages = { 492, 290, 129, 602, 152 };Now, use OrderBy to order the elements in ascending order. Then use the TakeLast() method to get specified number of elements from the end.marks.AsQueryable().OrderByDescending(s => s).Take(5);Let ... Read More

C# Queryable SequenceEqual() Method

Chandu yadav

Chandu yadav

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

81 Views

To check whether two sequences are equal or not, use the SequenceEqual() method.Firstly, set the sequences.Employee emp1 = new Employee { EmployeeRank = 4, EmpName = "Amit", EmpMarks = 90 }; Employee emp2 = new Employee { EmployeeRank = 5, EmpName = "Raman", EmpMarks = 95 }; List employee1 = ... Read More

C# Numeric (“N”) Format Specifier

Chandu yadav

Chandu yadav

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

2K+ Views

The numeric ("N") format specifier converts a number to a string of the following form −"-d, ddd, ddd.ddd…"Above, "-" is a negative number symbol if required, "d" is a digit (0-9), ", " indicates a group separator, "." is a decimal point symbolExample Live Demousing System; using System.Globalization; class Demo { ... Read More

Implicit conversion from 16-bit unsigned integer (ushort) to Decimal in C#

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 08:22:29

308 Views

UShort represents a 16-bit unsigned integer.To implicitly convert of a 16-bit unsigned integer to a decimal, firstly set a ushort value.ushort val = 193;To convert ushort to decimal, assign the value.decimal dec; dec = val;Let us see an example.Exampleusing System; public class Demo {    public static void Main() { ... Read More

Convert.ToString Method in C#

Chandu yadav

Chandu yadav

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

1K+ Views

Convert the specified value to its equivalent string using the ToString() method.Initialize a bool value.bool boolVal = false;Now, to convert it to a string, use the ToString() method.Convert.ToString(boolVal)The following is the complete example.Example Live Demousing System; public class Demo {    public static void Main() {       bool boolVal ... Read More

Clear a Hashtable in C#

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 08:11:04

383 Views

Clear a Hashtable, using the Clear() method in C#.The following is our Hashtable −Hashtable h = new Hashtable(); h.Add(1, "Amit"); h.Add(2, "Sachin"); h.Add(3, "Rahul");Use the clear method.h.Clear();If you will now try to display the Hashtable, nothing would get display since the Hashtable is empty.Example Live Demousing System; using System.Collections; public class ... Read More

Advertisements