Arjun Thakur has Published 1109 Articles

C# Program to check whether a node is a LinkedList or not

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 07:46:48

83 Views

Use the Contains() method to check whether a node is a LinkedList or not.Here is our LinkedList.string [] students = {"Beth", "Jennifer", "Amy", "Vera"}; LinkedList list = new LinkedList(students);Now, to check whether the node “Amy” is in the list or not, we will use the Contains() method as shown below ... Read More

LinkedList AddFirst method in C#

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 07:43:27

581 Views

In a Linked List, if you want to add a node at the first position, use AddFirst method.Let’s first set a LinkedList.string [] students = {"Jenifer", "Angelina", "Vera"}; LinkedList list = new LinkedList(students);Now, to add an element as a first node, use AddFirst() method.List.AddFirst(“Natalie”);Example Live Demousing System; using System.Collections.Generic; class Demo ... Read More

C# Program to add a node before the given node in a Linked List

Arjun Thakur

Arjun Thakur

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

186 Views

Declare a LinkedList and add nodes to it.string [] students = {"Tim", "Jack", "Henry", "David", "Tom"}; LinkedList list = new LinkedList(students);Let us add a new node.var newNode = list.AddLast("Kevin");Now, to add a node before the given node, use the AddBefore() method.list.AddBefore(newNode, "Matt");Let us now see the complete code.Example Live Demousing System; ... Read More

C# Program to create a LinkedList

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 07:32:15

217 Views

Firstly, set a string array.string [] students = {"Tim", "Jack", "Henry", "David", "Tom"};Now, add it to the LinkedList.LinkedList list = new LinkedList(students);The above creates a LinkedList and adds node to it.Let us see the complete example.Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {     ... Read More

C# Program to return specified number of elements from the end of an array

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 07:28:31

117 Views

Use the TakeLast() method to return elements from the end of an array.Let us first declare and initialize an array.int[] prod = { 110, 290, 340, 540, 456, 698, 765, 789};Now, let’s get the last three elements.IEnumerable units = prod.AsQueryable().TakeLast(3);Let us see the complete code.Example Live Demousing System; using System.Linq; using ... Read More

C# Program to cast a type to its IEnumerable equivalent

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 07:21:04

343 Views

Use the AsEnumerable() method to cast a type to its IEnumerable equivalent. It is an extension method.For our example, we have set an array.int[] myArr = new int[10]; myArr[0] = 1; myArr[1] = 2; myArr[2] = 3; myArr[3] = 4; myArr[4] = 5;Now, we have used the AsEnumerable() method to ... Read More

C# Program to check a string for whitespace characters or null

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 07:20:16

544 Views

This method returns true if the entered string has only whitespace characters or is null.Let’s say you are checking for whitespace character.bool val1 = string.IsNullOrWhiteSpace(“ “);The above returns True, since the string is a whitespace character. In the same way, check it for null using the IsNullOrWhiteSpace() method.Here is the ... Read More

C# OfType() Method

Arjun Thakur

Arjun Thakur

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

472 Views

Filter a collection on the basis of each of its elements type.Let’s say you have the following list with integer and string elements −list.Add("Katie"); list.Add(100); list.Add(200);To filter collection and get only elements with string type.var myStr = from a in list.OfType() select a;Work the same for integer type.var myInt = ... Read More

Month ("M", "m") Format Specifier in C#

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 07:05:26

251 Views

The Month standard format specifier represents a custom date and time format string.The format string is defined by the current DateTimeFormatInfo.MonthDayPattern property.The custom format string −MMMM ddExample Live Demousing System; using System.Globalization; class Demo {    static void Main() {       DateTime date = new DateTime(2018, 6, 11, 9, ... Read More

Why is f required while declaring floats in C#?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 06:59:13

586 Views

The f is a lowercase suffix set while declaring a float. It tells the compiler that the literal is of a specific type.Example Live Demousing System.IO; using System; public class Program {    public static void Main() {       float val = 30.22f;       Console.WriteLine(val);    } ... Read More

Advertisements