Csharp Articles

Page 90 of 196

What is the Count property of SortedList class in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 179 Views

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 More

How is a new object created in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 194 Views

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 More

How is an array initialized in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 196 Views

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 More

C# Program to Implement Stack with Push and Pop operations

Samual Sam
Samual Sam
Updated on 17-Mar-2026 804 Views

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 More

Where do we use scope Resolution Operator (::) in C#?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 851 Views

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 More

Why do we use comma operator in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 994 Views

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 More

How is an array declared in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 150 Views

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 More

Why is the Main() method use in C# static?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 3K+ Views

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

What is the maximum possible value of an integer in C# ?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 15K+ Views

The maximum possible value of a 32-bit signed integer (int) in C# is 2, 147, 483, 647. This value is also available through the constant int.MaxValue. However, C# provides several integer types with different ranges and maximum values. Integer Types and Their Maximum Values C# offers multiple integer data types, each with different storage sizes and value ranges − Type Size Range Maximum Value sbyte 8-bit signed -128 to 127 127 byte 8-bit unsigned 0 to 255 255 short 16-bit signed -32, 768 to 32, 767 ...

Read More

How to define custom methods in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 1K+ Views

To define a custom method in C#, you create a reusable block of code that performs a specific task. Methods help organize your code, make it more readable, and avoid repetition by allowing you to call the same functionality multiple times. Syntax Following is the syntax for defining a custom method in C# − (Parameter List) { Method Body } Method Components The following are the various elements of a method − Access Specifier − This determines the visibility of a method from other classes. ...

Read More
Showing 891–900 of 1,951 articles
« Prev 1 88 89 90 91 92 196 Next »
Advertisements