Found 2628 Articles for Csharp

How to get the remaining elements of the Tuple in C#?

AmitDiwan
Updated on 10-Dec-2019 12:20:39

48 Views

To get the remaining elements of the Tuple, the Rest property is used. The code is as follows −Example Live Demousing System; public class Demo {    public static void Main(String[] args){       var tuple1 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500, 2000);       var tuple2 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500, 2000);       Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));       Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode());       Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode());       Console.WriteLine("Tuple1 Item 1st = "+tuple1.Item1);       Console.WriteLine("Tuple2 Item 1st ... Read More

First occurrence in the List that matches the specified conditions in C#

AmitDiwan
Updated on 10-Dec-2019 12:15:55

386 Views

To get the first occurrence in the list that matches the specified conditions, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    private static bool demo(int i){       return ((i % 10) == 0);    }    public static void Main(String[] args){       List list = new List();       list.Add(200);       list.Add(215);       list.Add(310);       list.Add(500);       list.Add(600);       Console.WriteLine("List elements...");       foreach (int i in list){          Console.WriteLine(i);       } ... Read More

Finding the index of last element in the array in C#

AmitDiwan
Updated on 10-Dec-2019 12:13:23

177 Views

To find the index of the last element in the array, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(){       string[] products = new string[] { "Andy", "Mark", "Gary", "Andre"};       Console.WriteLine("One or more name begin with 'A'? = {0}",       Array.Exists(products, ele => ele.StartsWith("A")));       Console.WriteLine("Is the array having fixed size? = " + products.IsFixedSize);       Console.WriteLine("Is the array read only? = " + products.IsReadOnly);       Console.WriteLine("Is the array synchronized? = " + products.IsSynchronized);       Console.WriteLine("Index ... Read More

Find the first node in LinkedList containing the specified value in C#

AmitDiwan
Updated on 10-Dec-2019 12:10:27

56 Views

To find the first node in LinkedList containing the specified value, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(){       LinkedList list = new LinkedList();       list.AddLast("John");       list.AddLast("Tim");       list.AddLast("Kevin");       list.AddLast("Jacob");       list.AddLast("Emma");       list.AddLast("Ryan");       list.AddLast("Brad");       list.AddLast("Carl");       Console.WriteLine("LinkedList elements...");       foreach(string str in list){          Console.WriteLine(str);       }       LinkedListNode val = list.Find("Jacob");     ... Read More

Enumerator that iterates through the BitArray in C#

AmitDiwan
Updated on 10-Dec-2019 12:08:02

79 Views

Following is the code that iterates through the BitArray with Enumerator −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(){       BitArray arr1 = new BitArray(5);       BitArray arr2 = new BitArray(5);       arr1[0] = false;       arr1[1] = true;       arr1[2] = false;       arr1[3] = true;       arr1[4] = true;       Console.WriteLine("Enumerator that iterates through BitArray1");       IEnumerable demoEnum = arr1;       foreach(Object ob in demoEnum){          Console.WriteLine(ob);     ... Read More

Creating StringBuilder having specified capacity in C#

AmitDiwan
Updated on 10-Dec-2019 12:04:42

78 Views

To create StringBuilder having specified capacity, the code is as follows −Example Live Demousing System; using System.Text; public class Demo {    public static void Main(String[] args){       StringBuilder strBuilder1 = new StringBuilder("Tim");       StringBuilder strBuilder2 = new StringBuilder("Tom");       StringBuilder strBuilder3 = new StringBuilder();       StringBuilder strBuilder4 = new StringBuilder(5);       strBuilder2 = strBuilder3;       Console.WriteLine("Is StringBuilder3 equal to StringBuilder2? = "+strBuilder3.Equals(strBuilder2));       Console.WriteLine("StringBuider1 capacity = "+strBuilder1.Capacity);       Console.WriteLine("StringBuider2 capacity = "+strBuilder2.Capacity);       Console.WriteLine("StringBuider3 capacity = "+strBuilder3.Capacity);       Console.WriteLine("StringBuider4 capacity ... Read More

Creating a synchronized wrapper for a SortedList object in C#

AmitDiwan
Updated on 10-Dec-2019 12:02:00

85 Views

To create a synchronized wrapper for a SortedList object, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(){       SortedList sortedList = new SortedList();       sortedList.Add("1", "Tom");       sortedList.Add("2", "Ryan");       sortedList.Add("3", "Nathan");       Console.WriteLine("SortedList elements...");       foreach(DictionaryEntry d in sortedList){          Console.WriteLine("Key = "+d.Key + ", Value = " + d.Value);       }       SortedList sortedList2 = SortedList.Synchronized(sortedList);       Console.WriteLine("SortedList is synchronized? = "+sortedList2.IsSynchronized);    } }OutputThis will ... Read More

Count the number of key/value pairs in HybridDictionary in C#

AmitDiwan
Updated on 10-Dec-2019 11:58:43

58 Views

To count the number of key/value pairs in HybridDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       HybridDictionary dict1 = new HybridDictionary();       dict1.Add("A", "SUV");       dict1.Add("B", "MUV");       dict1.Add("C", "AUV");       Console.WriteLine("HybridDictionary1 elements...");       foreach(DictionaryEntry d in dict1){          Console.WriteLine(d.Key + " " + d.Value);       }       Console.WriteLine("Count of Key/value pairs in Dictionary1 = "+dict1.Count);       HybridDictionary dict2 = new HybridDictionary();     ... Read More

Copying the SortedList elements to an Array Object in C#

AmitDiwan
Updated on 10-Dec-2019 11:29:25

138 Views

To copy the SortedList elements to an Array Object, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args){       SortedList list = new SortedList();       list.Add("1", "AB");       list.Add("2", "CD");       list.Add("3", "EF");       list.Add("4", "GH");       list.Add("5", "IJ");       list.Add("6", "JK");       list.Add("7", "KL");       list.Add("8", "LM");       Console.WriteLine("SortedList elements...");       foreach(DictionaryEntry d in list){          Console.WriteLine("Key = "+d.Key + ", Value = ... Read More

Copying the HybridDictionary entries to an Array Instance in C#

AmitDiwan
Updated on 10-Dec-2019 11:26:47

59 Views

To copy the HybridDictionary entries to an Array Instance, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       HybridDictionary dict = new HybridDictionary();       dict.Add("1", "SUV");       dict.Add("2", "AUV");       dict.Add("3", "Utility Vehicle");       dict.Add("4", "MUV");       dict.Add("5", "Compact Car");       dict.Add("6", "Convertible");       Console.WriteLine("HybridDictionary Key and Value pairs...");       foreach(DictionaryEntry entry in dict){          Console.WriteLine("{0} and {1} ", entry.Key, entry.Value);       }   ... Read More

Advertisements