Server Side Programming Articles

Page 763 of 2109

How to use RightShift Operators in C#?

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

The right shift operator (>>) in C# moves the bits of the left operand to the right by the number of positions specified by the right operand. This operation effectively divides the number by powers of 2. Syntax Following is the syntax for the right shift operator − result = operand >> numberOfPositions; Where operand is the value whose bits will be shifted, and numberOfPositions specifies how many positions to shift right. How Right Shift Works The right shift operator moves each bit to the right by the specified number of positions. ...

Read More

How do you loop through a C# array?

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

To loop through an array in C#, you can use several loop types including for, foreach, while, and do...while loops. Each loop provides different ways to iterate through array elements and access their values. The most commonly used loops for arrays are the for loop (when you need index access) and the foreach loop (when you only need element values). Syntax Following is the syntax for different loop types with arrays − // for loop for (int i = 0; i < array.Length; i++) { // access array[i] } // ...

Read More

How to concatenate Two Arrays in C#?

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

To concatenate two arrays in C#, you can use several methods depending on your requirements. The most common approaches include using the Concat() method from LINQ, copying elements manually, or using Array.Copy(). Syntax Using LINQ Concat() method − var result = array1.Concat(array2).ToArray(); Using Array.Copy() method − Array.Copy(sourceArray, destinationArray, length); Using LINQ Concat() Method The Concat() method from LINQ is the most straightforward way to concatenate arrays. It creates a new array containing elements from both arrays − using System; using System.Linq; class Program { ...

Read More

What are control statements in C#?

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

Control statements in C# determine the flow of program execution by specifying which code blocks to execute based on conditions or how many times to repeat certain operations. These statements are fundamental building blocks that allow developers to create dynamic and responsive applications. C# provides several types of control statements that can be categorized into conditional statements (if, if-else, switch) and loop statements (for, while, do-while, foreach). Let's explore the main control statements with practical examples. if Statement An if statement executes a block of code only when a specified boolean condition evaluates to true. Syntax ...

Read More

What are destructors in C# programs?

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

A destructor is a special member function of a class that is executed whenever an object of its class goes out of scope or is garbage collected. It performs cleanup operations before the object is destroyed from memory. A destructor has exactly the same name as the class with a prefixed tilde (~), and it cannot have parameters or return values. It is automatically called by the garbage collector, not directly by the programmer. Syntax Following is the syntax for declaring a destructor − ~ClassName() { // cleanup code } ...

Read More

What are different methods of passing parameters in C#?

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

When a method with parameters is called, you need to pass the parameters to the method using one of the following three methods in C# − Value Parameters (Default) This method copies the actual value of an argument into the formal parameter of the function. Changes made to the parameter inside the function have no effect on the original argument because the method works with a copy of the value. Value Parameters - Copy by Value Main Method int a = 7 int b ...

Read More

Iterators in C#

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

An iterator in C# performs custom iteration over a collection using the yield keyword. It returns elements one at a time and remembers its current position, making it memory-efficient for large datasets. Iterators implement lazy evaluation, meaning values are generated only when requested. Syntax Following is the syntax for creating an iterator method − public static IEnumerable MethodName() { // logic here yield return value; // more logic yield return anotherValue; } The yield break statement can be ...

Read More

How to write the first program in C#?

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

Writing your first program in C# is the foundation of learning this powerful programming language. A C# program consists of several key components that work together to produce output. Let's explore the structure and elements of a basic C# program. Syntax Following is the basic structure of a C# program − using System; namespace NamespaceName { class ClassName { static void Main(string[] args) { // Program logic here ...

Read More

How to declare and initialize a dictionary in C#?

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

A Dictionary in C# is a collection that stores key-value pairs, where each key must be unique. It is part of the System.Collections.Generic namespace and provides fast lookups based on keys. Syntax Following is the syntax for declaring and initializing a Dictionary − Dictionary dictionaryName = new Dictionary(); Where TKey is the type of the key and TValue is the type of the value. You can also use the interface type for more flexibility − IDictionary dictionaryName = new Dictionary(); Using Dictionary.Add() Method The Add() method allows you ...

Read More

How to declare and initialize a list in C#?

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

A List in C# is a generic collection that stores elements in a resizable array. You can declare and initialize a List in several ways, depending on whether you want to add elements immediately or start with an empty collection. Syntax Following is the basic syntax for declaring a List − List listName = new List(); Following is the syntax for initializing a List with values − List listName = new List() { value1, value2, value3 }; Empty List Declaration ...

Read More
Showing 7621–7630 of 21,090 articles
« Prev 1 761 762 763 764 765 2109 Next »
Advertisements