Found 34494 Articles for Programming

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

301 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

596 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

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

85 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

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

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; 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

186 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

Implicit conversion from Int16 to Decimal in C#

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

161 Views

The short type represents a 16-bit signed integer i.e. Int16.To implicitly convert a 16-bit signed integer to a Decimal, firstly set a short value.short val = -32768;To convert short to decimal, assign the value.dec = val;Let us see another example.Example Live Demousing System; public class Demo {    public static void Main() {       short val = -32768;       decimal dec;       Console.WriteLine("Implicit conversion from Int16 to Decimal");       dec = val;       Console.WriteLine("Decimal : "+dec);    } }OutputImplicit conversion from Int16 to Decimal Decimal : -32768

Advertisements