Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 3166 of 3363
145 Views
Example Live Demousing System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { SortedList s = new SortedList(); s.Add("S1", "Electronics"); s.Add("S2", "Clothing"); s.Add("S3", "Applicances"); s.Add("S4", "Books"); s.Add("S5", "Accessories"); s.Add("S6", "Musical Instruments"); Console.WriteLine("Count = " + s.Count); } } }OutputCount = 6
267 Views
To find how many elements are added in the Stack class, you need to use the Count property.Let us first add elements in the Stack −Stack st = new Stack(); st.Push('H'); st.Push('I'); st.Push('J'); st.Push('K'); st.Push('L'); st.Push('M'); st.Push('N'); st.Push('O');Now count the number of elements in the Stack −Console.WriteLine("Count: "+st.Count);Let us see the complete code −Example Live Demousing System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { Stack st = new Stack(); st.Push('H'); st.Push('I'); st.Push('J'); ... Read More
185 Views
Use the Count property to find the count of elements of the Queue class. Set elements like the following declaration −Queue q = new Queue(); q.Enqueue(1); q.Enqueue(2); q.Enqueue(3); q.Enqueue(4);Then use the Count property to count the elements −q.CountThe following is an example showing how to work with Count property in Queue Class −Example Live Demousing System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { Queue q = new Queue(); q.Enqueue(1); q.Enqueue(2); q.Enqueue(3); q.Enqueue(4); Console.WriteLine("Total elements: {0} ", q.Count); Console.ReadKey(); } } }OutputTotal elements: 4
147 Views
To find the count of elements of Hashtable class, use the Count property. Firstly, set the Hashtable class with elements −Hashtable ht = new Hashtable(); ht.Add("One", "Tom"); ht.Add("Two", "Jack"); ht.Add("Three", "Peter"); ht.Add("Four", "Russel"); ht.Add("Five", "Brad"); ht.Add("Six", "Bradley"); ht.Add("Seven", "Steve"); ht.Add("Eight", "David");Now, count the number of elements using the Count property −ht.CountThe following is the complete example to learn about the usage of Hashtable Count property in C#.Example Live Demousing System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { Hashtable ht = new Hashtable(); ... Read More
151 Views
Count the number of elements in the BitArray class using the Count property.Let us first set our BitArray class −BitArray arr = new BitArray(10);Now use the Count property as shown below −Example Live Demousing System; using System.Collections; public class Demo { public static void Main() { BitArray arr = new BitArray(10); Console.WriteLine( "Count: {0}", arr.Count ); } }OutputCount: 10
358 Views
The capacity property in SortedList class has the maximum size of the SortedList.The default capacity of a SortedList is 16.You can try to run the following the code to implement Capacity property of SortedList class in C# −Example Live Demousing System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { SortedList s = new SortedList(); s.Add("S1", "Maths"); s.Add("S2", "Science"); s.Add("S3", "English"); s.Add("S4", "Economics"); Console.WriteLine("Capacity = " ... Read More
307 Views
The Count property in the ArrayList class counts the number of elements in the ArrayList.Firstly, add elements to the ArrayList −ArrayList arrList = new ArrayList(); arrList.Add(98); arrList.Add(55); arrList.Add(65); arrList.Add(34);Then get the count of the array list −arrList.CountThe following is the code to implement Count property in C# −Example Live Demousing System; using System.Collections; class Demo { public static void Main() { ArrayList arrList = new ArrayList(); arrList.Add(98); arrList.Add(55); arrList.Add(65); arrList.Add(34); Console.WriteLine("Count = " + arrList.Count); } }OutputCount = 4
3K+ Views
The capacity property in ArrayList class gets or sets the number of elements that the ArrayList can contain.Capacity is always greater than count. For capacity property −arrList.CapacityThe default capacity is 4. If 5 elements are there, then its capacity is doubled and would be 8. This goes on.You can try to run the following the code to implement Capacity property in C#. This also shows what we discussed above −Example Live Demousing System; using System.Collections; class Demo { public static void Main() { ArrayList arrList = new ArrayList(); arrList.Add(19); arrList.Add(44); ... Read More
971 Views
To find the number of dimensions of an array, use the Rank property.arr.RankHere, arr is our array −int[, ] arr = new int[3, 4];If you also want to get the rows and columns it has, then use the GetLength property −arr.GetLength(0); arr.GetLength(1);The following is the complete code −Example Live Demousing System; class Program { static void Main() { int[, ] arr = new int[3, 4]; Console.WriteLine(arr.GetLength(0)); Console.WriteLine(arr.GetLength(1)); // Length Console.WriteLine(arr.Length); Console.WriteLine("Upper Bound: {0}", arr.GetUpperBound(0).ToString()); Console.WriteLine("Lower Bound: ... Read More
18K+ Views
To find the length of an array, use the Array.Length() method.ExampleLet us see an example − Live Demousing System; class Program { static void Main(){ int[] arr = new int[10]; // finding length int arrLength = arr.Length; Console.WriteLine("Length of the array: "+arrLength); } }OutputLength of the array: 10Above, we have an array −int[] arr = new int[10];Now to find the length, we used the Length() method −int arrLength = arr.Length;