Chandu yadav has Published 1090 Articles

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

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

144 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

516 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

Clear a Hashtable in C#

Chandu yadav

Chandu yadav

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

498 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

How to handle empty collections in C#

Chandu yadav

Chandu yadav

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

456 Views

To handle empty collections, use the DefaultIfEmpty() method in C#.If an array is empty, then using this method will show the default method instead of displaying an error.Let’s say we have an empty list.List myList = new List();Now, use DefaultIfEmpty() method to display the default value.myList.DefaultIfEmpty();Example Live Demousing System; using System.Linq; ... Read More

How to negate the positive elements of an integer array in C#?

Chandu yadav

Chandu yadav

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

443 Views

The following is the array and its elements −int[] arr = { 10, 20, 15 };Set negative value to positive elements.if (arr[i] > 0) arr[i] = -arr[i];Loop the above until the length of the array.for (int i = 0; i < arr.Length; i++) {    Console.WriteLine(arr[i]);    if (arr[i] > ... Read More

C# Program to find the longest string from an array of strings using Lambda Expression

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 07:56:57

1K+ Views

The following is our string array −string[] arr = { "Java", "HTML", "CSS", "JavaScript"};Use the Aggregate method and set a Lambda Expression to find the string with more number of characters.Here, the resultant string should have more number of characters than the initial seed value i.e. “jQuery” here.Example Live Demousing System; ... Read More

Implicit conversion from 8-bit signed integer (SByte) to Decimal in C#

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 07:50:23

286 Views

SByte represents an 8-bit signed integer.To implicitly convert an 8-bit signed integer to a Decimal, firstly set an sbyte value.sbyte val = 51;To convert sbyte to decimal, assign the value.decimal d; d = val;Let us see another example.Exampleusing System; public class Demo {    public static void Main() {   ... Read More

Advertisements