Server Side Programming Articles

Page 764 of 2109

How to declare and initialize constant strings in C#?

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

To declare a constant string in C#, use the const keyword. Constants are immutable values that are set at compile-time and cannot be changed during program execution. Once initialized, attempting to modify a constant will result in a compile-time error. Syntax Following is the syntax for declaring and initializing a constant string − const string constantName = "value"; Constants must be initialized at the time of declaration and the value must be a compile-time constant expression. Key Rules for Constants Constants must be initialized at declaration − you cannot declare ...

Read More

How to declare and instantiate Delegates in C#?

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

C# delegates are similar to pointers to functions, in C or C++. A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime, making delegates powerful tools for implementing callback methods and event handling. Syntax Following is the syntax for declaring delegates − delegate Following is the syntax for instantiating delegates − delegateInstance = new (MethodName); Delegate Declaration and Instantiation 1. Declare Delegate delegate int ...

Read More

How to declare member function in C# interface?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 282 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 451 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 369 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 465 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
Showing 7631–7640 of 21,090 articles
« Prev 1 762 763 764 765 766 2109 Next »
Advertisements