Articles on Trending Technologies

Technical articles with clear explanations and examples

How to perform Matrix Addition using C#?

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

Matrix addition in C# involves adding corresponding elements from two matrices of the same dimensions. The matrices must have identical rows and columns for addition to be possible. The result is a new matrix where each element is the sum of the corresponding elements from the input matrices. Syntax Following is the basic syntax for matrix addition − int[, ] result = new int[rows, columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { ...

Read More

Different ways of Reading a file in C#

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

There are several ways to read files in C#, each suited for different scenarios. C# provides various classes in the System.IO namespace for file operations, including reading text files, binary files, and handling different data types efficiently. Using StreamReader for Text Files The StreamReader class is the most common way to read text files line by line. It provides efficient reading with proper resource management using the using statement − using System; using System.IO; class Program { static void Main(string[] args) { // ...

Read More

How to write multi-line comments in C#?

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

Multi-line comments in C# are comments that span more than one line. They are useful for adding detailed explanations, documenting code blocks, or temporarily disabling large sections of code during development. Syntax Multi-line comments in C# use the following syntax − /* This is a multi-line comment that can span multiple lines All text between /* and */ is ignored */ The compiler ignores everything between /* and */, making it perfect for lengthy explanations or code documentation. Basic Multi-line Comment Example using System; ...

Read More

Value parameters vs Reference parameters vs Output Parameters in C#

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

In C#, there are three ways to pass parameters to methods: value parameters, reference parameters, and output parameters. Each mechanism behaves differently in terms of how data is passed and whether changes affect the original variables. Syntax Following are the syntax forms for the three parameter types − // Value parameter (default) public void Method(int value) { } // Reference parameter public void Method(ref int value) { } // Output parameter public void Method(out int value) { } Value Parameters Value parameters copy the actual value of an argument into the ...

Read More

Print a 2 D Array or Matrix in C#

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

A 2D array or matrix in C# is a data structure that stores elements in rows and columns. To print a 2D array, you need to use nested loops to iterate through each row and column, displaying the elements in a formatted manner. Syntax Following is the syntax for declaring a 2D array − dataType[, ] arrayName = new dataType[rows, columns]; Following is the syntax for printing a 2D array using nested loops − for (int i = 0; i < rows; i++) { for (int j = ...

Read More

How to open hidden file using C#?

George John
George John
Updated on 17-Mar-2026 779 Views

To open a hidden file in C#, you need to first make it visible by removing the hidden attribute, then read its contents, and optionally restore the hidden attribute afterward. Hidden files have the FileAttributes.Hidden attribute set, which prevents them from being displayed in normal file explorers. Syntax Following is the syntax for removing the hidden attribute from a file − FileInfo file = new FileInfo(filePath); file.Attributes &= ~FileAttributes.Hidden; Following is the syntax for restoring the hidden attribute − file.Attributes |= FileAttributes.Hidden; Using FileInfo to Remove Hidden Attribute The ...

Read More

How to convert Trigonometric Angles in Radians using C#?

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

To convert trigonometric angles from degrees to radians in C#, multiply the degree value by Math.PI/180. Most trigonometric functions in C# expect angles in radians, so this conversion is essential for accurate calculations. Syntax Following is the syntax for converting degrees to radians − double radians = degrees * (Math.PI / 180.0); Following is the syntax for converting radians to degrees − double degrees = radians * (180.0 / Math.PI); Converting Degrees to Radians Example The following example shows how to properly convert degrees to radians before using ...

Read More

Quickly convert Decimal to other bases in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 795 Views

Converting decimal numbers to other bases in C# can be efficiently accomplished using a Stack data structure. The stack naturally handles the reversal of digits that occurs during the conversion process, making it an ideal choice for base conversion algorithms. How It Works The conversion process involves repeatedly dividing the decimal number by the target base and storing the remainders. Since division produces digits in reverse order, a stack helps retrieve them in the correct sequence: Divide the decimal number by the target base Push the remainder onto the stack Update the number to the quotient ...

Read More

What is the C# equivalent for the Java System.exit(0)?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 2K+ Views

The C# equivalent for Java's System.exit(0) is the Environment.Exit() method. This method terminates the current process and returns an exit code to the operating system, just like its Java counterpart. Syntax Following is the syntax for using Environment.Exit() − Environment.Exit(exitCode); Parameters exitCode − An integer value returned to the operating system. Use 0 to indicate successful termination, and non-zero values to indicate different error conditions. Exit Code Conventions Exit Code Meaning 0 Process completed successfully 1 General error ...

Read More

DirectoryNotFoundException in C#

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

The DirectoryNotFoundException in C# is thrown when an application attempts to access a directory that does not exist on the file system. This exception is part of the System.IO namespace and commonly occurs during file and directory operations. Syntax The exception is automatically thrown by the .NET framework when directory operations fail − public class DirectoryNotFoundException : SystemException Common methods that can throw this exception include − Directory.GetDirectories(path); Directory.GetFiles(path); DirectoryInfo directoryInfo = new DirectoryInfo(path); When DirectoryNotFoundException Occurs Here is an example that demonstrates when this exception occurs by trying ...

Read More
Showing 11281–11290 of 61,297 articles
Advertisements