Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 765 of 2109
What is the Count property of ArrayList class in C#?
The Count property in the ArrayList class returns the number of elements currently stored in the ArrayList. This property is read-only and provides an efficient way to determine the size of the collection. Syntax Following is the syntax for accessing the Count property − int count = arrayListName.Count; Return Value The Count property returns an int value representing the total number of elements in the ArrayList. Using Count Property with ArrayList First, create an ArrayList and add elements to it − ArrayList arrList = new ArrayList(); arrList.Add(98); arrList.Add(55); arrList.Add(65); ...
Read MoreWhat is the Count property of Hashtable class in C#?
The Count property of the Hashtable class in C# returns the total number of key-value pairs stored in the hashtable. It is a read-only property that provides an efficient way to determine the size of the collection. Syntax Following is the syntax for using the Count property − int count = hashtable.Count; Return Value The Count property returns an int value representing the number of key-value pairs currently stored in the hashtable. Using Count Property with Basic Operations The following example demonstrates how to use the Count property to track the ...
Read MoreWhat is the Count property of SortedList class in C#?
The Count property of the SortedList class in C# returns the number of key-value pairs stored in the collection. This read-only property is useful for determining the size of the sorted list and performing operations that depend on the collection's current size. Syntax Following is the syntax for accessing the Count property − int count = sortedList.Count; Return Value The Count property returns an int value representing the total number of key-value pairs currently stored in the SortedList. Example The following example demonstrates how to use the Count property to get ...
Read MoreHow is a new object created in C#?
In C#, creating objects is fundamental to object-oriented programming. An object is an instance of a class that represents a real-world entity. Objects allow you to access class members including fields, properties, and methods using the dot operator. Syntax Following is the basic syntax for creating a new object in C# − ClassName objectName = new ClassName(); You can also initialize an object with constructor parameters − ClassName objectName = new ClassName(parameter1, parameter2); Object Creation Process When you create an object using the new keyword, the following steps occur: ...
Read MoreHow is an array initialized in C#?
All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. In C#, arrays must be properly initialized before you can use them to store and access data. Array Declaration vs Initialization Firstly, declare an array − int[] rank; But declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array. Array is a reference type, so you need to use the new keyword to create an instance ...
Read MoreC# Program to Implement Stack with Push and Pop operations
A Stack in C# is a Last-In-First-Out (LIFO) data structure that allows elements to be added and removed from only one end, called the top. The Stack class in the System.Collections namespace provides built-in methods for implementing stack operations. The two primary operations of a stack are Push() to add elements and Pop() to remove elements. Additionally, the Peek() method allows you to view the top element without removing it. Syntax Following is the syntax for creating a Stack and using basic operations − Stack stackName = new Stack(); stackName.Push(element); // ...
Read MoreWhere do we use scope Resolution Operator (::) in C#?
The scope resolution operator (::) in C# is used to access types within namespaces, especially when dealing with namespace aliases or when there are naming conflicts. Unlike C++ where it's primarily used for global variables, in C# it specifically relates to namespace resolution. The scope resolution operator helps distinguish between types that share the same name but exist in different namespaces. It's particularly useful when using namespace aliases or the global keyword. Syntax Following is the syntax for using the scope resolution operator with namespace aliases − alias::TypeName Following is the syntax for ...
Read MoreWhy do we use comma operator in C#?
The comma operator in C# serves as a separator and allows multiple operations within a single statement. It is most commonly used in for loops for multiple variable initialization and increment operations, and as a separator in method parameter lists. Syntax Following is the syntax for using comma operator in for loop initialization and increment − for (int i = value1, j = value2; condition; i++, j++) { // loop body } Following is the syntax for using comma as separator in method parameters − MethodName(parameter1, parameter2, parameter3); ...
Read MoreHow is an array declared in C#?
To declare an array in C#, you specify the data type followed by square brackets and the array name. Arrays in C# are reference types that store multiple elements of the same data type in a contiguous memory location. Syntax Following is the basic syntax for declaring an array − datatype[] arrayName; To declare and initialize an array with a specific size − datatype[] arrayName = new datatype[size]; To declare and initialize an array with values − datatype[] arrayName = {value1, value2, value3, ...}; Here − ...
Read MoreWhy is the Main() method use in C# static?
The Main() method in C# is declared as static because it serves as the entry point of the program and must be callable without creating an instance of the class. When a C# program starts, no objects exist yet, so the runtime needs a way to begin execution without instantiation. Why Main() Must Be Static The static keyword allows the method to be called directly on the class rather than on an instance. Since the program hasn't created any objects when it starts, the Main() method must be accessible without instantiation − Program ...
Read More