Found 26504 Articles for Server Side Programming

Index of first occurrence in StringCollection in C#?

AmitDiwan
Updated on 16-Dec-2019 08:03:56

193 Views

To get the index of first occurrence in StringCollection, the code is as follows −Example Live Demousing System; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringCollection strCol = new StringCollection();       strCol.Add("Accessories");       strCol.Add("Books");       strCol.Add("Electronics");       strCol.Add("Books");       Console.WriteLine("StringCollection elements...");       foreach (string res in strCol) {          Console.WriteLine(res);       }       strCol.Insert(2, "Headphone");       Console.WriteLine("StringCollection elements...UPDATED");       foreach (string res in strCol) {          Console.WriteLine(res); ... Read More

Getting an enumerator for the entire ArrayList in C#?

AmitDiwan
Updated on 16-Dec-2019 07:59:23

116 Views

To get an enumerator for the entire ArrayList in C#, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       ArrayList list1 = new ArrayList();       list1.Add("A");       list1.Add("B");       list1.Add("C");       list1.Add("D");       list1.Add("E");       list1.Add("F");       list1.Add("G");       list1.Add("H");       list1.Add("I");       Console.WriteLine("Elements in ArrayList1...");       foreach (string res in list1) {          Console.WriteLine(res);       }   ... Read More

Check whether a SortedList object contains a specific key in C#?

AmitDiwan
Updated on 16-Dec-2019 07:40:32

138 Views

To check whether a SortedList object contains a specific key in C#, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main() {       SortedList list = new SortedList ();       list.Add("A", "Books");       list.Add("B", "Electronics");       list.Add("C", "Appliances");       list.Add("D", "Pet Supplies");       list.Add("E", "Clothing");       list.Add("F", "Footwear");       Console.WriteLine("Value associated with key E = "+list["E"]);       list["E"] = "HDD";       Console.WriteLine("Value associated with key E [Updated] = "+list["E"]);   ... Read More

How to check whether a List contains the elements that match the specified conditions in C#?

AmitDiwan
Updated on 16-Dec-2019 07:34:49

445 Views

To check whether a List contains the elements that match the specified conditions in C#, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    private static bool demo(int i) {       return ((i % 3) == 0);    }    public static void Main(String[] args) {       List list = new List();       list.Add(255);       list.Add(315);       list.Add(410);       list.Add(500);       list.Add(600);       list.Add(710);       list.Add(800);       list.Add(1000);       Console.WriteLine("List elements...");   ... Read More

How to get Synchronize access to the Stack in C#?

AmitDiwan
Updated on 16-Dec-2019 07:30:01

124 Views

To get synchronize access to the Stack, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main() {       Stack stack = new Stack();       stack.Push(100);       stack.Push(200);       stack.Push(300);       stack.Push(400);       stack.Push(500);       Console.WriteLine("Stack...");       foreach(Object ob in stack) {          Console.WriteLine(ob);       }       Console.WriteLine("Count of elements = "+stack.Count);             Console.WriteLine("Synchronize access...");       lock(stack.SyncRoot) {       ... Read More

Get the specified members of the current Type in C#?

AmitDiwan
Updated on 16-Dec-2019 07:15:22

110 Views

To get the specified members of the current Type, the code is as follows −Example Live Demousing System; using System.Reflection; public class Demo {    public static void Main() {       Type type = typeof(Subject);       try {          FieldInfo fieldInfo = type.GetField("SubName");          MemberInfo[] info = type.GetMember("SubName");          Console.Write("Members = ");          for (int i = 0; i < info.Length; i++)          Console.WriteLine(" {0}", info[i]);          Console.WriteLine("FieldInfo = {0}", fieldInfo);       }       catch ... Read More

Create a Queue from another collection in C#?

AmitDiwan
Updated on 16-Dec-2019 07:12:14

96 Views

To create a Queue from another collection, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       Queue queue = new Queue();       queue.Enqueue("One");       queue.Enqueue("Two");       queue.Enqueue("Three");       Console.WriteLine("Queue elements...");       foreach(string str in queue) {          Console.WriteLine(str);       }       Console.WriteLine("Array elements...");       Queue arr = new Queue(queue.ToArray());       foreach(string str in arr) {          Console.WriteLine(str);       }   ... Read More

Count the total number of elements in the List in C#?

AmitDiwan
Updated on 16-Dec-2019 07:03:45

610 Views

To count the total number of elements in the List, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(String[] args) {       List list = new List();       list.Add("One");       list.Add("Two");       list.Add("Three");       list.Add("Four");       list.Add("Five");       Console.WriteLine("Elements in List1...");       foreach (string res in list) {          Console.WriteLine(res);       }       Console.WriteLine("Count of elements in list = "+list.Count);       list.Clear();       ... Read More

StringDictionary Class in C#?

AmitDiwan
Updated on 16-Dec-2019 06:50:36

217 Views

The StringDictionay class implements a hash table with the key and the value strongly typed to be strings rather than objects.Following are the properties of the StringDictionary class −Sr.NoProperty & Description1CountGets the number of key/value pairs in the StringDictionary.2IsSynchronizedGets a value indicating whether access to the StringDictionary is synchronized (thread safe).3tem[String]Gets or sets the value associated with the specified key.4KeysGets a collection of keys in the StringDictionary..5SyncRootGets an object that can be used to synchronize access to the StringDictionary.6ValuesGets a collection of values in the StringDictionary.Following are some of the methods of the StringDictionary class −Sr.NoMethods & Description1Add(String, String)Adds an ... Read More

How to get Synchronize access to the HybridDictionary in C#?

AmitDiwan
Updated on 16-Dec-2019 06:45:29

115 Views

To get synchronize access to HybridDictionary, the code is as follows −Exampleusing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       HybridDictionary dict1 = new HybridDictionary();       dict1.Add("A", "Books");       dict1.Add("B", "Electronics");       dict1.Add("C", "Smart Wearables");       dict1.Add("D", "Pet Supplies");       dict1.Add("E", "Clothing");       dict1.Add("F", "Footwear");       Console.WriteLine("HybridDictionary1 elements...");       foreach(DictionaryEntry d in dict1) {          Console.WriteLine(d.Key + " " + d.Value);       }       Console.WriteLine("Is the HybridDictionary1 ... Read More

Advertisements