Found 2587 Articles for Csharp

Clear a Linked List in C#

George John
Updated on 23-Jun-2020 08:05:42

202 Views

Clear a LinkedList using Clear() method.Let us first set a LinkedList.string [] employees = {"Patrick", "Robert", "John", "Jacob", "Jamie"}; LinkedList list = new LinkedList(employees);Now, let us clear the LinkedList.list.Clear();Let us see the complete code.Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       string [] employees = {"Patrick", "Robert", "John", "Jacob", "Jamie"};       LinkedListlist = new LinkedList(employees);       foreach (var emp in list) {          Console.WriteLine(emp);       }       // clearing list       list.Clear();       Console.WriteLine("LinkedList after removing the ... Read More

C# Enum Parse Method

Ankith Reddy
Updated on 23-Jun-2020 08:07:12

2K+ Views

The Parse method in Enum converts the string representation of the name or numeric value of enum constants to an equivalent enumerated object.The following is our enumeration.enum Vehicle { Car, Bus, Truck, Motobike };Now, use the GetNames() method in a loop to get the enum values. Parse them using the Enum.Parse() method as shown below −Enum.Parse(typeof(Vehicle)Example Live Demousing System; public class Demo {    enum Vehicle { Car, Bus, Truck, Motobike };    public static void Main() {       Console.WriteLine("The enumeration...");       foreach (string v in Enum.GetNames(typeof(Vehicle))) {          Console.WriteLine("{0} = {1:D}", v, Enum.Parse(typeof(Vehicle), ... Read More

C# Enum ToString() Method

karthikeya Boyini
Updated on 23-Jun-2020 08:06:27

3K+ Views

The ToString() method converts the value of this instance to its equivalent string representation.Firstly, set an enum.enum Vehicle { Car, Bus, Truck, Motobike };To convert it to an equivalent string representation, use ToString().Vehicle.Car.ToString("d")Example Live Demousing System; public class Demo {    enum Vehicle { Car, Bus, Truck, Motobike };    public static void Main() {       Console.WriteLine("Vehicle.Car = {0}", Vehicle.Car.ToString("d"));       Console.WriteLine("Vehicle.Bus = {0}", Vehicle.Bus.ToString("d"));    } }OutputVehicle.Car = 0 Vehicle.Bus = 1

Short Date ("d") Format Specifier

Samual Sam
Updated on 23-Jun-2020 08:07:54

288 Views

The "d" format specifier represents a custom date and time format string.The format string is defined by culture's DateTimeFormatInfo.ShortDatePattern property.The custom format string is −MM/dd/yyyyExample Live Demousing System; using System.Globalization; class Demo {    static void Main() {       DateTime myDate = new DateTime(2018,9, 09);       Console.WriteLine(myDate.ToString("d", DateTimeFormatInfo.InvariantInfo));       Console.WriteLine(myDate.ToString("d", CultureInfo.CreateSpecificCulture("en-US")));    } }Output09/09/2018 9/9/2018

LinkedList Clear() Method in C#

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

695 Views

Use the Clear() method to clear a LinkedList. This will remove all the nodes from the LinkedList.Let’s say the following is our LinkedList −int [] num = {30, 65, 80, 95, 110, 135}; LinkedList list = new LinkedList(num);To clear the LinkedList.list.Clear();Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       int [] num = {30, 65, 80, 95, 110, 135};       LinkedList list = new LinkedList(num);       foreach (var n in list) {          Console.WriteLine(n);       }       // clear       list.Clear();       Console.WriteLine("No node in the LinkedList now...");       foreach (var n in list) {          Console.WriteLine(n);       }    } }Output30 65 80 95 110 135 No node in the LinkedList now...

Implicit conversion from 8-bit signed integer (SByte) to Decimal in C#

Chandu yadav
Updated on 23-Jun-2020 07:50:23

261 Views

SByte represents an 8-bit signed integer.To implicitly convert an 8-bit signed integer to a Decimal, firstly set an sbyte value.sbyte val = 51;To convert sbyte to decimal, assign the value.decimal d; d = val;Let us see another example.Exampleusing System; public class Demo {    public static void Main() {       sbyte val = 39;       decimal d;       Console.WriteLine("Implicit conversion from 8-bit signed integer (sbyte) to Decimal");       d = val;       Console.WriteLine("Decimal = "+dec);    } }

C# Program to rename a file

Samual Sam
Updated on 23-Jun-2020 07:51:35

2K+ Views

Use the Move method to rename a file.Let’s say the file name is −D:\tom.txtNow, to update it to the following, use the Move() method.D:\tim.txtLet us see the complete code.Exampleusing System; using System.IO; public class Demo {    public static void Main() {       File.Move(@"D:\tom.txt", @"D:\tim.txt");       Console.WriteLine("File moved successfully!");    } }

Year Month ("Y") Format Specifier in C#

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

316 Views

The Year Month format specifier represents a custom date and time format string.It is defined by the DateTimeFormatInfo.YearMonthPattern property.Here is the custom format string.yyyy MMMMExample Live Demousing System; using System.Globalization; class Demo {    static void Main() {       DateTime date = new DateTime(2018, 9, 7, 7, 55, 20);       Console.WriteLine(date.ToString("Y",CultureInfo.CreateSpecificCulture("en-US")));    } }OutputSeptember 2018

C# Program to remove a node at the end of the Linked List

karthikeya Boyini
Updated on 23-Jun-2020 07:52:28

175 Views

The following is our LinkedList.string [] employees = {"Patrick", "Robert", "John", "Jacob", "Jamie"}; LinkedList list = new LinkedList(employees);Now, let’s say you need to remove the last node i.e. “Jamie”. For that, use the RemoveLast() method.list.RemoveLast();Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       string [] employees = {"Patrick", "Robert", "John", "Jacob", "Jamie"};       LinkedList list = new LinkedList(employees);       foreach (var emp in list) {          Console.WriteLine(emp);       }       // removing last node       list.RemoveLast();       Console.WriteLine("LinkedList ... Read More

LinkedList RemoveLast() Method in C#

Ankith Reddy
Updated on 23-Jun-2020 07:53:04

426 Views

Firstly, declare a LinkedList and add nodes.int [] num = {92, 98, 110, 130, 145, 170, 230, 240, 250, 300, 330}; LinkedList myList = new LinkedList(num);Remove the last node from the LinkedList using the RemoveLast() method.myList.RemoveLast();Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       int [] num = {92, 98, 110, 130, 145, 170, 230, 240, 250, 300, 330};       LinkedList myList = new LinkedList(num);       foreach (var n in myList) {          Console.WriteLine(n);       }       // removing last node       myList.RemoveLast();       Console.WriteLine("LinkedList after removing the last node...");       foreach (var n in myList) {          Console.WriteLine(n);       }    } }Output92 98 110 130 145 170 230 240 250 300 330 LinkedList after removing the last node... 92 98 110 130 145 170 230 240 250 300

Advertisements