Found 34489 Articles for Programming

C# into keyword

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

86 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

LinkedList AddFirst method in C#

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

585 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 {    static void Main() {       string [] students = {"Jenifer", "Angelina", "Vera"};       LinkedList list = new LinkedList(students);       foreach (var stu in list) {          Console.WriteLine(stu);       }       // add a node   ... Read More

Convert.ToInt32 Method in C#

karthikeya Boyini
Updated on 23-Jun-2020 07:43:49

5K+ Views

Use the Convert.ToInt32() method to convert a specified value to a 32-bit signed integer.Let us take a double variable.double doubleNum = 11.53;Now, we will convert it to Int32 using the Convert.ToInt32 method.int intNum; ntNum = Convert.ToInt32(doubleNum);Example Live Demousing System; public class Demo {    public static void Main() {       double doubleNum = 11.53;       int intNum;       intNum = Convert.ToInt32(doubleNum);       Console.WriteLine("Converted {0} to {1}", doubleNum, intNum);    } }OutputConverted 11.53 to 12

C# Program to return a collection with repeated elements

Chandu yadav
Updated on 23-Jun-2020 07:44:12

235 Views

To return a collection with repeated elements in C#, use Enumerable.Repeat method.It is part of System.Linq namespace.Let’s say you need to repeat a number twice, for that set the number and the frequency of repetition.Enumerable.Repeat(50, 2);Now assign it to a variable and display it.Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       // repeating element 50, two times       var num = Enumerable.Repeat(50, 2);       // displayig repeating elements       foreach (int ele in num) {          Console.WriteLine(ele);       }    } }Output50 50

C# Program to invert the order of elements in a sequence

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

137 Views

Set a string.char[] ch = { 'd', 'r', 'i', 'v', 'e' }; Console.Write("String = foreach(char arr in ch) Console.Write(arr);Now, use Queryable Reverse() method to invert the order of elements.IQueryable res = ch.AsQueryable().Reverse();Let us see the complete code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       char[] ch = { 'd', 'r', 'i', 'v', 'e' };       Console.Write("String = ");       foreach(char arr in ch)       Console.Write(arr);       IQueryable res = ch.AsQueryable().Reverse();       Console.Write("Reversed = ");       foreach (char c in res)       Console.Write(c);    } }OutputString = drive Reversed = evird

Advertisements