Articles on Trending Technologies

Technical articles with clear explanations and examples

How to iterate over a C# list?

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

A List in C# is a generic collection that stores elements of the same type. There are several ways to iterate over a C# list, each with its own advantages depending on your specific needs. Syntax Following is the basic syntax for declaring and initializing a list − List listName = new List(); Following are the common iteration syntaxes − // foreach loop foreach(var item in list) { // process item } // for loop for(int i = 0; i < list.Count; i++) { // ...

Read More

C# Linq First() Method

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

The First() method in C# LINQ is used to return the first element from a collection such as arrays, lists, or any IEnumerable sequence. It throws an exception if the collection is empty. Syntax Following is the syntax for the First() method − collection.First() collection.First(predicate) Parameters predicate (optional) − A function to test each element for a condition. Return Value Returns the first element in the collection or the first element that satisfies the condition. Throws InvalidOperationException if no element is found. Using First() Without Predicate The ...

Read More

Decimal.Floor() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 591 Views

The Decimal.Floor() method in C# rounds a specified decimal number down to the nearest integer toward negative infinity. This means it always rounds down, even for negative numbers. Syntax Following is the syntax − public static decimal Floor(decimal val); Parameters val − The decimal value to round down to the nearest integer. Return Value Returns a decimal value representing the largest integer less than or equal to the specified decimal number. Decimal.Floor() Behavior Number Line ...

Read More

C# Program to Illustrate Lower Triangular Matrix

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

A lower triangular matrix is a square matrix where all elements above the main diagonal are zero. In other words, for any element at position (i, j), if j > i, then the element is zero. The main diagonal consists of elements where the row index equals the column index (i = j). Below the diagonal, elements can have any non-zero values. Syntax The condition to check if an element should be displayed or set to zero − if (i >= j) // Display the actual element else ...

Read More

What are unary operators in C#?

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

Unary operators in C# are operators that operate on a single operand. They perform various operations such as incrementing, decrementing, negating, or getting the size of a data type. Complete List of Unary Operators Operator Name Description + Unary plus Indicates positive value (rarely used) - Unary minus Negates the value ! Logical NOT Inverts boolean value ~ Bitwise complement Inverts all bits ++ Increment Increases value by 1 -- Decrement Decreases value by 1 (type) Cast Converts to ...

Read More

Logical Operators on String in C#

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

Logical operators in C# are used to perform logical operations on boolean expressions. When working with strings, these operators are commonly used to evaluate string conditions and create compound boolean expressions for string validation and comparison logic. Logical Operators Operator Description Example && Called Logical AND operator. Returns true if both operands are true. (str != null && str.Length > 0) || Called Logical OR operator. Returns true if at least one operand is true. (str == "" || str == null) ! Called Logical NOT operator. ...

Read More

How to empty a C# list?

Giri Raju
Giri Raju
Updated on 17-Mar-2026 14K+ Views

To empty a C# list, use the Clear() method. This method removes all elements from the list and sets the count to zero. The Clear() method is the most efficient way to empty a list as it removes all elements in a single operation. Syntax Following is the syntax for the Clear() method − listName.Clear(); Parameters The Clear() method does not take any parameters. Return Value The Clear() method does not return any value. It modifies the list in-place by removing all elements. Using Clear() Method The following example ...

Read More

EnumerateFiles method in C#

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

The Directory.EnumerateFiles() method in C# is used to enumerate all files in a specified directory. It returns an IEnumerable collection of file paths, making it memory-efficient for large directories as it processes files lazily (one at a time) rather than loading all file paths into memory at once. Syntax Following is the basic syntax for the Directory.EnumerateFiles() method − Directory.EnumerateFiles(path) Directory.EnumerateFiles(path, searchPattern) Directory.EnumerateFiles(path, searchPattern, searchOption) Parameters path − The directory path to search for files. searchPattern − The search string to match file names (e.g., "*.*" for all files, "*.txt" for text ...

Read More

Type.GetTypeFromHandle() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 226 Views

The Type.GetTypeFromHandle() method in C# is used to get the Type object referenced by the specified RuntimeTypeHandle. This method is particularly useful when working with type handles obtained from reflection operations or when you need to convert a type handle back to its corresponding Type object. Syntax Following is the syntax − public static Type GetTypeFromHandle(RuntimeTypeHandle handle); Parameters The method accepts the following parameter − handle − A RuntimeTypeHandle that refers to a specific type. Return Value Returns a Type object that represents the type referenced ...

Read More

C# program to Illustrate Upper Triangular Matrix

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

An upper triangular matrix is a square matrix where all elements below the main diagonal are zero. In an upper triangular matrix, elements are preserved only on or above the main diagonal (where row index ≤ column index). Upper Triangular Matrix 1 2 3 4 0 5 6 7 0 0 8 9 0 0 0 10 Zero below diagonal Non-zero on/above diagonal Logic To display an upper triangular matrix, we use the condition i

Read More
Showing 11191–11200 of 61,297 articles
Advertisements