Found 2587 Articles for Csharp

C# Program to skip a specified number of elements of an array

karthikeya Boyini
Updated on 23-Jun-2020 07:47:50

621 Views

The following is our array −int[] points = { 210, 250, 300, 350, 420};Use skip() method to skip elements. Add the number as an argument that displays the number of elements to be returned.IEnumerable skipEle = points.AsQueryable().OrderByDescending(s => s).Skip(3);Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       int[] points = { 210, 250, 300, 350, 420};       Console.WriteLine("Initial array...");           foreach (int res in points)       Console.WriteLine(res);       IEnumerable skipEle = points.AsQueryable().OrderByDescending(s => s).Skip(3);       Console.WriteLine("Skipped 3 elements...");       foreach (int res in skipEle)       Console.WriteLine(res);    } }OutputInitial array... 210 250 300 350 420 Skipped 3 elements... 250 210

LinkedList AddAfter method in C#

Chandu yadav
Updated on 23-Jun-2020 07:48:28

1K+ Views

Set a LinkedList.int [] num = {1, 2, 3, 4, 5}; LinkedList list = new LinkedList(num);Now add a node at the end using AddLast() method.var newNode = list.AddLast(20);To add a node after the above added node, use the AddAfter() method.list.AddAfter(newNode, 30);Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       int [] num = {1, 2, 3, 4, 5};       LinkedList list = new LinkedList(num);       foreach (var n in list) {          Console.WriteLine(n);       }       // adding a node at the ... Read More

Implicit conversion from UInt64 to Decimal in C#

Samual Sam
Updated on 23-Jun-2020 07:48:53

416 Views

The ulong type represents a 64-bit unsigned integer i.e. UInt64.To implicitly convert a 64-bit unsigned integer to a Decimal, firstly set UInt64 value.ulong val = ulong.MaxValue;To convert ulong to decimal, assign the value.decimal dec; dec = val;Let us see the above example.Example Live Demousing System; public class Demo {    public static void Main() {       ulong val = ulong.MaxValue;       decimal dec;       Console.WriteLine("Implicit conversion from Ulong to Decimal");       dec = val;       Console.WriteLine("Decimal : "+dec);    } }OutputImplicit conversion from Ulong to Decimal Decimal : 18446744073709551615

C# Convert.ToInt32 Method

George John
Updated on 23-Jun-2020 07:49:14

760 Views

Use Convert.ToInt32 method to convert text to an integer.Firstly, set a string.string str = "12";Now, use the Convert.ToInt32() method the above string to number.Convert.ToInt32(str);Let us see the complete example.Example Live Demousing System; class Program {    static void Main() {       string str = "12";       Console.WriteLine("String: "+str);       int n = Convert.ToInt32(str);       Console.WriteLine("Number: "+n);    } }OutputString: 12 Number: 12

C# int.TryParse Method

karthikeya Boyini
Updated on 02-Sep-2023 14:17:10

75K+ Views

Convert a string representation of number to an integer, using the int.TryParse() method in C#. If the string cannot be converted, then the int.TryParse() method returns false i.e. a Boolean value.Let’s say you have a string representation of a number.string myStr = "12";Now to convert it to an integer, use the int.TryParse(). It will get converted and will return True.int.TryParse(myStr, out a);Example Live Demousing System.IO; using System; class Program {    static void Main() {       bool res;       int a;       string myStr = "12";       res = int.TryParse(myStr, out a);   ... Read More

C# into keyword

Ankith Reddy
Updated on 23-Jun-2020 07:40:16

134 Views

Set query in a select clause using the into operator.The following is our list with Employee details −IList employee = new List() {    new Employee() { EmpID = 1, EmpName = "Tom", EmpMarks = 90, Rank = 8} ,    new Employee() { EmpID = 2, EmpName = "Anne", EmpMarks = 60, Rank = 21 } ,    new Employee() { EmpID = 3, EmpName = "Jack", EmpMarks = 76, Rank = 18 } ,    new Employee() { EmpID = 4, EmpName = "Amy" , EmpMarks = 67, Rank = 20} , };Now, fetch employee name that ends ... Read More

C# Program to find the average of a sequence of numeric values

Samual Sam
Updated on 23-Jun-2020 07:40:42

4K+ Views

Use the Linq Average() method to find the average of a sequence of numeric values.Firstly, set a sequence.List list = new List { 5, 8, 13, 35, 67 };Now, use the Queryable Average() method to get the average.Queryable.Average(list.AsQueryable());Example Live Demousing System; using System.Linq; using System.Collections.Generic; class Demo {    static void Main() {       List list = new List { 5, 8, 13, 35, 67 };       double avg = Queryable.Average(list.AsQueryable());       Console.WriteLine("Average = "+avg);    } }OutputAverage = 25.6

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

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

259 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; using System.Collections.Generic; class Demo {    static void Main() {       string [] students = {"Tim", "Jack", "Henry", "David", "Tom"};       LinkedList list = new LinkedList(students);       foreach (var stu in list) {          Console.WriteLine(stu);       }     ... Read More

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

karthikeya Boyini
Updated on 23-Jun-2020 07:41:13

228 Views

Set a LinkedList with nodes.string [] students = {"Tim", "Jack", "Henry", "David", "Tom"}; LinkedList list = new LinkedList(students);Now, use the AddLast() method to add a node at the last position.list.AddLast("Kevin");Here is the complete code with the updated LinkedList.Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       string [] students = {"Tim", "Jack", "Henry", "David", "Tom"};       LinkedList list = new LinkedList(students);       foreach (var stu in list) {          Console.WriteLine(stu);       }       // adding a node at the end     ... Read More

Implicit conversion from Char to Decimal in C#

Ankith Reddy
Updated on 23-Jun-2020 07:42:22

2K+ Views

To implicitly convert char to a Decimal, firstly set a char.char c = 'p';To convert char to decimal, assign the value.decimal dec; dec = c;Let us see the above example.Example Live Demousing System; public class Demo {    public static void Main() {       char c = 'p';       decimal dec;       Console.WriteLine("Implicit conversion from Char to Decimal");       dec = c;       Console.WriteLine("Decimal : "+dec);    } }OutputImplicit conversion from Char to Decimal Decimal : 112

Advertisements