Csharp Articles

Page 89 of 196

How to declare member function in C# interface?

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

To declare member functions in C# interfaces, you define method signatures without implementations. The implementing class must provide the actual method bodies using the public access modifier. Syntax Following is the syntax for declaring member functions in an interface − public interface InterfaceName { ReturnType MethodName(parameters); void AnotherMethod(); } The implementing class must provide implementations for all interface methods − public class ClassName : InterfaceName { public ReturnType MethodName(parameters) { // implementation } ...

Read More

How to declare variables in C#?

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

Each variable in C# has a specific type, which determines the size and layout of the variable's memory, the range of values that can be stored within that memory, and the set of operations that can be applied to the variable. Variables must be declared before they can be used. Declaration tells the compiler what type of data the variable will hold and reserves memory accordingly. Syntax Following is the basic syntax for declaring variables in C# − ; You can also declare multiple variables of the same type in a single ...

Read More

How to define a single-dimensional array in C Sharp?

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

An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type stored at contiguous memory locations. A single-dimensional array in C# is a linear collection of elements of the same data type. It allows you to store multiple values in a single variable and access them using an index. Syntax Following is the syntax for declaring a single-dimensional array − datatype[] arrayName = new datatype[size]; Following is the syntax for initializing an array with ...

Read More

Command Line arguments in C#

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

Command line arguments in C# allow you to pass data to your program when it starts. These arguments are received through the string[] args parameter in the Main method, making your applications flexible and configurable from the command line. When you create a C# program, the Main method can accept command line arguments as an array of strings. Each argument passed from the command line becomes an element in this array. Syntax Following is the syntax for accepting command line arguments in the Main method − static void Main(string[] args) { // ...

Read More

How to use sizeof() operator to find the size of a data type or a variable in C#

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

The sizeof operator in C# returns the size of a data type in bytes. It can only be used with value types and is particularly useful when working with unmanaged code or memory allocation scenarios. Syntax Following is the syntax for using the sizeof operator − sizeof(datatype) For example, to find the size of an int data type − sizeof(int); Key Rules The sizeof operator can only be used with value types, not reference types. It returns the size in bytes. For built-in ...

Read More

How do you find the length of an array in C#?

George John
George John
Updated on 17-Mar-2026 18K+ Views

To find the length of an array in C#, use the Length property (not a method). The Length property returns the total number of elements in the array as an integer value. Syntax Following is the syntax for using the Length property − int length = arrayName.Length; Parameters arrayName − The array whose length you want to find Return Value The Length property returns an int value representing the total number of elements in the array. Example Let us see an example − using System; ...

Read More

How do you find the number of dimensions of an array in C#?

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

To find the number of dimensions of an array in C#, use the Rank property. This property returns an integer representing the total number of dimensions in the array. Syntax Following is the syntax for getting the number of dimensions − int dimensions = arr.Rank; For getting the length of specific dimensions, use the GetLength() method − int lengthOfDimension = arr.GetLength(dimensionIndex); Using Rank Property The Rank property works with single-dimensional, multi-dimensional, and jagged arrays − using System; class Program { static void Main() ...

Read More

What is the Capacity property of an ArrayList class in C#?

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

The Capacity property in the ArrayList class gets or sets the number of elements that the ArrayList can contain. This property represents the internal array size, which is automatically managed by the ArrayList to optimize performance. The capacity is always greater than or equal to the count of elements. When elements are added and the capacity is exceeded, the ArrayList automatically doubles its capacity to accommodate more elements. Syntax Following is the syntax for accessing the Capacity property − arrayListName.Capacity You can also set the capacity explicitly − arrayListName.Capacity = newCapacityValue; ...

Read More

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

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

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 More

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

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

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 More
Showing 881–890 of 1,951 articles
« Prev 1 87 88 89 90 91 196 Next »
Advertisements