Csharp Articles

Page 89 of 196

SortedMap Interface in C#

Samual Sam
Samual Sam
Updated on 11-Mar-2026 583 Views

Java has SortedMap Interface, whereas an equivalent of it in C# is SortedList.SortedList collection in C# use a key as well as an index to access the items in a list.A sorted list is a combination of an array and a hash table. It contains a list of items that can be accessed using a key or an index. If you access items using an index, it is an ArrayList, and if you access items using a key, it is a Hashtable. The collection of items is always sorted by the key value.Let us see an example to work with ...

Read More

Date format validation using C# Regex

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 16K+ Views

Use the DateTime.TryParseExact method in C# for Date Format validation.They method converts the specified string representation of a date and time to its DateTime equivalent. It checks whether the entered date format is correct or not.Exampleusing System; using System.Globalization; namespace Demo {    class Program {       static void Main(string[] args) {          DateTime d;          bool chValidity = DateTime.TryParseExact(          "08/14/2018",          "MM/dd/yyyy",          CultureInfo.InvariantCulture,          DateTimeStyles.None,          out d);          Console.WriteLine(chValidity);       }    } }OutputTrue

Read More

C# program to list the difference between two lists

Samual Sam
Samual Sam
Updated on 11-Mar-2026 2K+ Views

To get the difference between two lists, firstly set two lists in C# −// first list List < string > list1 = new List < string > (); list1.Add("A"); list1.Add("B"); list1.Add("C"); list1.Add("D"); // second list List < string > list2 = new List < string > (); list2.Add("C"); list2.Add("D"); foreach(string value in list2) {    Console.WriteLine(value); }To get the difference, use IEnumerable and Except() as shown below. The difference is shown in the third list −IEnumerable < string > list3; list3 = list1.Except(list2);The following is the complete code −Exampleusing System; using System.Collections.Generic; using System.Linq; public class Demo { ...

Read More

C# program to merge two sorted arrays into one

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

Set two arrays that you wish to merge −int[] arr1 = new int[5] {    5,    15,    25,    30,    47 }; int[] arr2 = new int[5] {    55,    60,    76,    83,    95 };Now take a third array that would merge both the above arrays −int[] merged = new int[10];The following is the code that merges two arrays into the third array in C# −Exampleusing System; using System.Collections.Generic; class Program {    static void Main() {       int i = 0;       int j = 0; ...

Read More

Flow control in try catch finally in C#

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 769 Views

The flow control in try, catch, and finally can be understood using the following example. Here, we are dividing two numbers −Exampleusing System; namespace ErrorHandlingApplication {    class DivNumbers {       int result;       DivNumbers() {          result = 0;       }       public void division(int num1, int num2) {          try {             result = num1 / num2;          } catch (DivideByZeroException e) {             Console.WriteLine("Exception caught: {0}", e);     ...

Read More

How to convert Decimal to Binary using C#?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 437 Views

Let’s say we want to convert the number 48 to binary.Firstly, set it and use the / and % operators and loop until the value is greater than 1 −decVal = 48; while (decVal >= 1) {    val = decVal / 2;    a += (decVal % 2).ToString();    decVal = val; }Now, display every bit of the binary as shown in the complete code −Exampleusing System; using System.Collections.Generic; using System.Text; namespace Demo {    class MyApplication {       static void Main(string[] args) {          int decVal;          int ...

Read More

How to check if String is Palindrome using C#?

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 532 Views

Let’s say we need to find that the following string is Palindrome or not −str = "Level";For that, convert the string into character array to chec each character −char[] ch = str.ToCharArray();Now find the reverse −Array.Reverse(ch);Use the Equals method to find whether the reverse is equal to original array or not −bool res = str.Equals(rev, StringComparison.OrdinalIgnoreCase);The following is the complete code −Exampleusing System; namespace Demo {    class Program {       static void Main(string[] args) {          string str, rev;          str = "Level";          char[] ch = ...

Read More

LinkedList in C#

Samual Sam
Samual Sam
Updated on 11-Mar-2026 2K+ Views

System.Collections.Generic namespace is available in C# for LinkedList. The LinkedList class allows insertion and deletion of elements from the list at a fast pace.C# LinkedList class uses the concept of linked list. It allows us to insert and delete elements fastly. It can have duplicate elements. It is found in System.Collections.Generic namespace.Here is an example −Exampleusing System; using System.Collections.Generic; class Demo {    static void Main() {       LinkedList < string > l = new LinkedList < string > ();       l.AddLast("one");       l.AddLast("two");       l.AddLast("three");       foreach(var ele in l) {          Console.WriteLine(ele);       }    } }Outputone two three

Read More

Semaphore in C#

Arjun Thakur
Arjun Thakur
Updated on 11-Mar-2026 4K+ Views

The semaphore class lets you set a limit on the number of threads that have access to a critical section. The class is used to control access to a pool of resources. System.Threading.Semaphore is the namespace for Semaphore because it has all the methods and properties required to implement Semaphore.For using a semaphore in C#, you just need to instantiate an instance of a Semaphore object. It has minimum of two arguments −Reference−MSDNSr.No.Constructor & Description1Semaphore(Int32, Int32)Initializes a new instance of the Semaphore class, specifying the initial number of entries and the maximum number of concurrent entries.2Semaphore(Int32, Int32, String) −Initializes a ...

Read More

Main thread vs child thread in C#

varma
varma
Updated on 11-Mar-2026 955 Views

Main ThreadThe first thread to be executed in a process is called the main thread. When a C# program starts execution, the main thread is automatically created.Child ThreadThe threads created using the Thread class are called the child threads of the main thread.Here is an example showing how to create a main and child thread −Exampleusing System; using System.Threading; namespace Demo {    class Program {       static void Main(string[] args) {          Thread th = Thread.CurrentThread;          th.Name = "MainThread";          Console.WriteLine("This is {0}", th.Name);          Console.ReadKey();       }    } }OutputThis is MainThread

Read More
Showing 881–890 of 1,951 articles
« Prev 1 87 88 89 90 91 196 Next »
Advertisements