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
Programming Articles
Page 853 of 2547
Logical 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 MoreWhat are user defined data types in C#?
User-defined data types in C# allow developers to create custom types beyond the built-in primitive types. The main user-defined data types in C# are structures, enumerations, classes, interfaces, and delegates. This article focuses on structures and enumerations as fundamental user-defined types. Structure In C#, a structure is a value type data type that helps you group related data of various types into a single unit. The struct keyword is used for creating a structure. Syntax public struct StructName { // fields, properties, methods, constructors public dataType field1; ...
Read MoreHow to iterate over a C# tuple?
A tuple in C# is a data structure that holds multiple values of different types. Since tuples have a fixed structure, you cannot iterate over them using traditional loops like arrays or collections. Instead, you access tuple elements individually using their Item properties or through deconstruction. Syntax To create a tuple and access its elements − // Creating a tuple Tuple tuple = new Tuple(100, "Tom"); // Accessing individual elements tuple.Item1 // first element tuple.Item2 // second element For modern C# (7.0+), you can use tuple literals − var ...
Read MoreFunc generic type in C#
The Func generic type in C# is a built-in delegate that represents a method which takes zero or more input parameters and returns a value. It provides a convenient way to store anonymous methods, lambda expressions, and regular methods that return a value. Syntax Following is the syntax for declaring a Func delegate − Func funcName; // No parameters, returns TResult Func funcName; ...
Read MoreC# Math.DivRem Method
The Math.DivRem method in C# performs integer division and returns both the quotient and remainder in a single operation. This is more efficient than performing separate division and modulo operations when you need both results. Syntax Following is the syntax for the Math.DivRem method − public static int Math.DivRem(int a, int b, out int result); public static long Math.DivRem(long a, long b, out long result); Parameters a − The dividend (number to be divided) b − The divisor (number to divide by) result − An out parameter that receives the remainder ...
Read MoreType.GetTypeHandle() Method in C#
The Type.GetTypeHandle() method in C# is used to get the runtime type handle for a specified object. A RuntimeTypeHandle provides a lightweight way to reference a type without holding a direct reference to the Type object itself, which is useful in performance-critical scenarios and interop operations. Syntax Following is the syntax for the Type.GetTypeHandle() method − public static RuntimeTypeHandle GetTypeHandle(object o) Parameters o − The object for which to get the type handle. Return Value Returns a RuntimeTypeHandle structure that represents the type of the specified object. Using ...
Read More