Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to iterate over a C# list?
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 MoreC# Linq First() Method
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 MoreDecimal.Floor() Method in C#
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 MoreC# Program to Illustrate Lower Triangular Matrix
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 MoreWhat are unary operators in C#?
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 MoreLogical Operators on String in C#
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 MoreHow to empty a C# list?
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 MoreEnumerateFiles method in C#
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 MoreType.GetTypeFromHandle() Method in C#
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 MoreC# program to Illustrate Upper Triangular Matrix
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