Chandu yadav has Published 1163 Articles

C# Program to skip elements from a sequence as long as the specified condition is true

Chandu yadav

Chandu yadav

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

172 Views

Use the SkipWhile() method to skip elements from a sequence as long as the specified condition is true.The following is the array −int[] marks = { 35, 42, 48, 88, 55, 90, 95, 85 };Here is the condition.s => s >= 50As long as the above condition is true, the ... Read More

C# Enum IsDefined Method

Chandu yadav

Chandu yadav

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

2K+ Views

The IsDefined method returns true if a given integral value, or its name as a string, is present in a specified enum.The following is our enum −enum Subjects { Maths, Science, English, Economics };The above is initialized by default i.e.Maths = 0, Science = 1, English = 2, Economics = ... Read More

C# Program to add a node at the first position in a Linked List

Chandu yadav

Chandu yadav

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

332 Views

Firstly, set a LinkedList with nodes.string [] students = {"Tim", "Jack", "Henry", "David", "Tom"}; LinkedList list = new LinkedList(students);To add a node at the first position, use the AddFirst() method.list.AddFirst("Amit");Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       string [] students = {"Tim", ... Read More

C# Queryable LongCount Method

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 07:01:10

130 Views

Use the Linq LongCount method to get the count of elements.The following is our string array −string[] emp = { "Jack", "Mark"};Now, use the LongCount() method.emp.AsQueryable().LongCount();Here is the complete code.Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo {    static void Main() {       string[] emp = ... Read More

C# Program to filter array elements based on a predicate

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 06:55:01

3K+ Views

Set an array.int[] arr = { 40, 42, 12, 83, 75, 40, 95 };Use the Where clause and predicate to get elements above 50.IEnumerable myQuery = arr.AsQueryable() .Where((a, index) => a >= 50);Let us see the complete code −Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { ... Read More

Convert.ToInt16 Method in C#

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 15:46:02

623 Views

Convert a specified value to a 16-bit signed integer using the Convert.ToInt16 method in C#.We have a double variable with a value initialized to it.double doubleNum = 3.456;Now, let us convert it to Int16 i.e. short.short shortNum; shortNum = Convert.ToInt16(doubleNum);Here is the complete example −Example Live Demousing System; public class Demo ... Read More

Represent Int64 as a Binary string in C#

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 15:44:15

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. 2 for Binary.Int64 represents a 64-bit signed integer.Firstly, set an Int64 variable.long val = 753458;Now, convert it to binary string by including 2 as the second ... Read More

C# int.Parse Vs int.TryParse Method

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 15:38:27

4K+ Views

Convert a string representation of number to an integer, using the int.TryParse and intParse method in C#.If the string cannot be converted, then the int.TryParse method returns false i.e. a Boolean value, whereas int.Parse returns an exception.Let us see an example of int.Parse method −Example Live Demousing System.IO; using System; class ... Read More

Where to use #region directive in C#?

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 15:34:39

4K+ Views

It lets you specify a block of code that you can expand or collapse when using the outlining feature of the Visual Studio Code Editor. It should be terminated with #endregion.Let us see how to define a region using #region.#region NewClass definition public class NewClass {    static void Main() ... Read More

C# program to get the file name in C#

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 15:03:07

558 Views

Set the path name in a string −string myPath = "D:ew\quiz.txt";Now, use the GetFileName() method to get the name of the file −Path.GetFileName(myPath)The following is the complete code −Example Live Demousing System; using System.IO; namespace Demo {    class Program {       static void Main(string[] args) {     ... Read More

Advertisements