Arjun Thakur

Arjun Thakur

749 Articles Published

Articles by Arjun Thakur

Page 12 of 75

C# Enum GetValues Method

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 2K+ Views

The Enum.GetValues() method in C# retrieves an array containing the values of all constants in a specified enumeration. This method is useful when you need to iterate through all enum values dynamically or perform operations on the entire set of enum values. Syntax Following is the syntax for the Enum.GetValues() method − public static Array GetValues(Type enumType) Parameters enumType − The Type of the enumeration whose values you want to retrieve. Return Value Returns an Array containing the values of the constants in the specified enumeration. Using GetValues() ...

Read More

How to access elements from multi-dimensional array in C#?

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

To access elements from a multi-dimensional array in C#, you specify indices for each dimension using square brackets with comma-separated values. For example, a[2, 1] accesses the element at row 3, column 2 (using zero-based indexing). Syntax Following is the syntax for accessing elements from a multi-dimensional array − arrayName[index1, index2, ...indexN] For a 2D array, you use two indices − int element = array[rowIndex, columnIndex]; Understanding Array Indexing Multi-dimensional arrays use zero-based indexing, meaning the first element is at index [0, 0]. Consider this 4×2 array structure − ...

Read More

How to open a plain text file in C#?

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

In C#, you can open and read a plain text file using the StreamReader class from the System.IO namespace. The StreamReader provides methods to read character data from a stream in a particular encoding. Syntax Following is the basic syntax for opening a text file with StreamReader − StreamReader sr = new StreamReader("filepath"); For proper resource management, use the using statement − using (StreamReader sr = new StreamReader("filepath")) { // Read file content } Using StreamReader to Read Text Files The most common approach is ...

Read More

What is the C# equivalent of C++ friend keyword?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 3K+ Views

In C++, the friend keyword allows external functions or classes to access private and protected members of a class. C# does not have a direct equivalent to the friend keyword, but there are several approaches to achieve similar functionality. Understanding the friend Concept A friend function in C++ is defined outside a class but has access to all private and protected members of that class. While C# doesn't support this directly, it provides alternative mechanisms to control access between closely related classes. Using Nested Classes The closest equivalent to C++ friend functionality is using nested classes. ...

Read More

How command line arguments are passed in main method in C#?

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

The Main() method is the entry point of a C# application and can accept command line arguments through its args parameter. These arguments allow users to pass data to the program when it starts, making applications more flexible and configurable. Syntax The standard syntax for the Main() method with command line arguments is − static void Main(string[] args) The args parameter is a string array that contains all command line arguments passed to the program − // args[0] = first argument // args[1] = second argument // args.Length = total number of ...

Read More

Static binding vs Dynamic binding in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 3K+ Views

Polymorphism can be static or dynamic. In static polymorphism, the method to be called is determined at compile time. In dynamic polymorphism, the decision is made at runtime based on the actual object type. Static Binding (Compile-Time Polymorphism) Static binding links a function with an object during compile time. It is also called early binding. This is achieved through method overloading and operator overloading. Static Binding Process Source Code Method calls Compiler Resolves calls ...

Read More

How to read inputs as integers in C#?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 32K+ Views

To read inputs as integers in C#, you need to first read the input as a string using Console.ReadLine() and then convert it to an integer using methods like Convert.ToInt32() or int.Parse(). The process involves two steps: reading the user input as a string and converting it to an integer data type for mathematical operations. Syntax Following is the basic syntax for reading integer input − string input = Console.ReadLine(); int number = Convert.ToInt32(input); You can also use int.Parse() method − int number = int.Parse(Console.ReadLine()); Using Convert.ToInt32() Method ...

Read More

Difference between Abstract Class and Interface in C#

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

Both abstract classes and interfaces in C# define contracts for derived classes to implement, but they serve different purposes and have distinct characteristics. An interface defines a contract with method signatures that implementing classes must provide, while an abstract class can provide both abstract methods and concrete implementations that derived classes inherit. Understanding the key differences helps you choose the right approach for your object-oriented design needs. Syntax Following is the syntax for declaring an interface − public interface IInterfaceName { void Method1(); int Property1 { get; ...

Read More

How to generate a string randomly using C#?

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

Generating random strings in C# is useful for creating passwords, test data, or unique identifiers. There are several approaches to generate random strings, from simple character-based methods to more advanced techniques using predefined character sets. Syntax Following is the basic syntax for generating random strings using Random class − Random random = new Random(); char randomChar = (char)random.Next(startValue, endValue); Following is the syntax using a character array − char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); char randomChar = chars[random.Next(chars.Length)]; Using ASCII Values for Random String Generation This method generates random characters by ...

Read More

What is the operator that concatenates two or more string objects in C#?

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

The + operator is used to concatenate two or more string objects in C#. This operator provides a simple and intuitive way to combine strings, making it one of the most commonly used string operations in C# programming. Syntax Following is the basic syntax for string concatenation using the + operator − string result = string1 + string2; string result = string1 + string2 + string3; Using + Operator for String Concatenation Example 1: Basic String Concatenation using System; class Program { static void Main() { ...

Read More
Showing 111–120 of 749 articles
« Prev 1 10 11 12 13 14 75 Next »
Advertisements