Programming Articles - Page 2263 of 3366

Convert Stack to array in C#

AmitDiwan
Updated on 06-Dec-2019 06:46:53

428 Views

To convert stack to the array, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(){       Stack stack = new Stack();       stack.Push("AB");       stack.Push("CD");       stack.Push("FG");       stack.Push("KL");       Console.WriteLine("Array...");       foreach(string i in stack){          Console.WriteLine(i);       }       string[] strArr = stack.ToArray();       Console.WriteLine("Convert Stack to Array...");       foreach(string i in strArr){          Console.WriteLine(i);       }   ... Read More

Convert Queue To array in C#

AmitDiwan
Updated on 06-Dec-2019 06:44:18

353 Views

To convert queue to the array, 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(100);       queue.Enqueue(200);       queue.Enqueue(300);       queue.Enqueue(400);       queue.Enqueue(500);       queue.Enqueue(600);       queue.Enqueue(700);       queue.Enqueue(800);       queue.Enqueue(900);       queue.Enqueue(1000);       Console.WriteLine("Queue...");       foreach(int i in queue){          Console.WriteLine(i);       }       int[] intArr = queue.ToArray(); ... Read More

Get the number of elements contained in the Queue in C#

AmitDiwan
Updated on 06-Dec-2019 06:39:22

204 Views

To get the number of elements contained in the Queue, 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("Gary");       queue.Enqueue("Jack");       queue.Enqueue("Ryan");       queue.Enqueue("Kevin");       queue.Enqueue("Mark");       queue.Enqueue("Jack");       queue.Enqueue("Ryan");       queue.Enqueue("Kevin");       Console.Write("Count of elements = ");       Console.WriteLine(queue.Count);       queue.Clear();       Console.Write("Count of elements (updated) = ");       Console.WriteLine(queue.Count);   ... Read More

Get the number of elements contained in SortedList in C#

AmitDiwan
Updated on 06-Dec-2019 06:32:18

109 Views

To get the number of elements contained in the SortedList, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args){       SortedList sortedList = new SortedList();       sortedList.Add("A", "1");       sortedList.Add("B", "2");       sortedList.Add("C", "3");       sortedList.Add("D", "4");       sortedList.Add("E", "5");       sortedList.Add("F", "6");       sortedList.Add("G", "7");       sortedList.Add("H", "8");       sortedList.Add("I", "9");       sortedList.Add("J", "10");       Console.WriteLine("SortedList elements...");       foreach(DictionaryEntry d in sortedList){ ... Read More

Get an enumerator that iterates through Collection in C#

AmitDiwan
Updated on 06-May-2020 08:47:25

116 Views

To get an enumerator that iterates through Collection, the code is as follows −Example Live Demousing System; using System.Collections.ObjectModel; public class Demo {    public static void Main(){       Collection col = new Collection();       col.Add("Andy");       col.Add("Kevin");       col.Add("John");       col.Add("Kevin");       col.Add("Mary");       col.Add("Katie");       col.Add("Barry");       col.Add("Nathan");       col.Add("Mark");       Console.WriteLine("Count of elements = "+ col.Count);       Console.WriteLine("Iterating through the collection...");       var enumerator = col.GetEnumerator();       while (enumerator.MoveNext()) { ... Read More

What are the scoping rules for lambda expressions in Java?

raja
Updated on 10-Jul-2020 08:51:15

570 Views

There are different scoping rules for lambda expression in Java. In lambda expressions, this and super keywords are lexically scoped means that this keyword refers to the object of the enclosing type and the super keyword refers to the enclosing superclass. In the case of an anonymous class, they are relative to the anonymous class itself. Similarly, local variables declared in lambda expression conflicts with variables declared in the enclosing class. In the case of an anonymous class, they are allowed to shadow variables in the enclosing class.Example@FunctionalInterface interface TestInterface {    int calculate(int x, int y); } class Test {    public ... Read More

Get the number of elements actually contained in the ArrayList in C#

AmitDiwan
Updated on 06-Dec-2019 06:25:55

120 Views

To get the number of elements actually contained in the ArrayList, 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

Get the minimum value in the SortedSet in C#

AmitDiwan
Updated on 06-Dec-2019 06:21:36

149 Views

To get the minimum value in the SortedSet, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(){       SortedSet set1 = new SortedSet();       set1.Add("AB");       set1.Add("BC");       set1.Add("CD");       set1.Add("EF");       Console.WriteLine("Elements in SortedSet1...");       foreach (string res in set1){          Console.WriteLine(res);       }       Console.WriteLine("Maximum element in SortedSet1 = " + set1.Max);       Console.WriteLine("Minimum element in SortedSet1 = " + set1.Min);       SortedSet ... Read More

Get an enumerator that iterates through the Hashtable in C#

AmitDiwan
Updated on 06-Dec-2019 06:18:12

367 Views

To get an enumerator that iterates through the Hashtable, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(){       Hashtable hash = new Hashtable(10);       hash.Add("1", "A");       hash.Add("2", "B");       hash.Add("3", "C");       hash.Add("4", "D");       hash.Add("5", "E");       hash.Add("6", "F");       hash.Add("7", "G");       hash.Add("8", "H");       hash.Add("9", "I");       hash.Add("10", "J");       Console.WriteLine("Hashtable Key and Value pairs...");       foreach(DictionaryEntry entry in ... Read More

Removing all entries from HybridDictionary in C#

AmitDiwan
Updated on 06-Dec-2019 06:13:35

107 Views

To remove all entries from 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", "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("Count of Key/value pairs ... Read More

Advertisements