George John has Published 1081 Articles

Clear a Linked List in C#

George John

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 ... Read More

Implicit conversion from Int32 to Decimal in C#

George John

George John

Updated on 23-Jun-2020 07:54:11

2K+ Views

The int type represents a 32-bit signed integer i.e. Int32.To implicitly convert an Int32 to a Decimal, firstly set a Int32 value.int val = 392;To convert Int32 to decimal, assign the value.decimal d; d = val;Let us see another example.Exampleusing System; public class Demo {    public static void Main() ... Read More

C# Convert.ToInt32 Method

George John

George John

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

757 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: ... Read More

C# program to remove the first occurrence of a node in a Linked List

George John

George John

Updated on 23-Jun-2020 07:45:07

132 Views

The following is our LinkedList list with nodes.string [] students = {"Katie", "Jennifer", "Amy", "Vera"}; LinkedList list = new LinkedList(students);Now let us remove a node with the string element “Vera”.For that, use Remove() method.list.Remove("Vera");Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       string ... Read More

Display the default if element is not found in a C# List

George John

George John

Updated on 23-Jun-2020 07:37:32

136 Views

We have a list without any element.List val = new List { };To display the default and avoid any error, use the FirstorDefault() method.val.AsQueryable().FirstOrDefault();You can also change the value to be displayed as default.Let us see the code.Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo {    static void ... Read More

Different Star Pattern Programs in C#

George John

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

Generate current month in C#

George John

George John

Updated on 23-Jun-2020 07:29:56

11K+ Views

To display current month, firstly use “Now“ to get the current date.DateTime dt = DateTime.Now;Now, use the Month property to get the current month.dt.MonthLet us see the complete code.Example Live Demousing System; using System.Linq; public class Demo {    public static void Main() {       DateTime dt = DateTime.Now; ... Read More

C# Fixed-Point (“F”) Format Specifier

George John

George John

Updated on 23-Jun-2020 07:25:28

1K+ Views

The ("F") format specifier converts a number to a string of the following form −"-ddd.ddd…"Above, "d" indicates a digit (0-9).Let us see an example.Here, if we will set (“F3”) format specifier to add three values after decimal places, for let’s say, 212.212.000The following is another example −Example Live Demousing System; using ... Read More

Calculate minutes between two dates in C#

George John

George John

Updated on 23-Jun-2020 07:22:38

21K+ Views

Firstly, set the two dates.DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25);Now, calculate the difference between two dates.TimeSpan ts = date2 - date1;To calculate minutes.ts.TotalMinutesLet us see the complete code.Example Live Demousing System; using System.Linq; public class Demo { ... Read More

C# DateTime to add days to the current date

George John

George John

Updated on 23-Jun-2020 07:18:39

7K+ Views

Firstly, get the current date.DateTime.TodayNow, use AddDays() method to add days to the current date. Here, we are adding 10 days to the current date.DateTime.Today.AddDays(10)Let us see the complete code −Example Live Demousing System; using System.Linq; public class Demo {    public static void Main() {       Console.WriteLine("Today = ... Read More

Advertisements