Server Side Programming Articles - Page 2441 of 2650

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

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

233 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

257 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

770 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

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

346 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

213 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

C# Program to create a LinkedList

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

311 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() {       string [] students = {"Tim","Jack","Henry","David","Tom"};       LinkedList list = new LinkedList(students);       foreach (var stu in list) {          Console.WriteLine(stu);       }    } }OutputTim Jack Henry David Tom

C# Program to merge sequences

karthikeya Boyini
Updated on 23-Jun-2020 07:32:51

217 Views

Let’s add two sequences.Integer Array.int[] intArray = { 1, 2, 3, 4, 5, 6, 7, 8 };String Array.string[] stringArray = { "Depp", "Cruise", "Pitt", "Clooney", "Sandler", "Affleck", "Tarantino" };Now to merge both the above sequences, use the Zip method.ntArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two);Let us see the complete code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       int[] intArray = { 1, 2, 3, 4, 5, 6, 7, 8 };       string[] stringArray = { "Depp", "Cruise", "Pitt", "Clooney", "Sandler", "Affleck", "Tarantino"   ... Read More

Different Star Pattern Programs in C#

George John
Updated on 23-Jun-2020 07:34:56

25K+ Views

Like any other programming languages such as C, C++, Java, we can easily display start pattern programs in C#.Let us see them one by one.Example Live Demousing System.IO; using System; class Program {    static void Main() {       for (int i = 1; i

Advertisements