George John

George John

789 Articles Published

Articles by George John

Page 10 of 79

How to insert an item into a C# list by using an index?

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

The Insert() method in C# allows you to add an item to a List at a specific index position. This method shifts existing elements to make room for the new item, automatically increasing the list's size. Syntax Following is the syntax for the Insert() method − list.Insert(index, item); Parameters index − The zero-based index at which the item should be inserted. item − The object to insert into the list. How It Works When you use Insert(), the method shifts all elements at and after ...

Read More

C# Program to match all the digits in a string

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

To match all digits in a string, we can use regular expressions (Regex) in C#. Regular expressions provide a powerful way to search for patterns in text, including numeric values. The System.Text.RegularExpressions namespace contains the Regex class that allows us to define patterns and find matches within strings. Syntax Following is the syntax for matching digits using Regex − MatchCollection matches = Regex.Matches(inputString, @"\d+"); The regular expression pattern \d+ breaks down as follows − \d − matches any single digit (0-9) + − matches one or more consecutive occurrences ...

Read More

What is run time polymorphism in C#?

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

Runtime polymorphism in C# allows the same method call to behave differently depending on the actual type of object at runtime. This is achieved through method overriding, also known as dynamic binding or late binding. It is implemented using abstract classes and virtual functions. In runtime polymorphism, the method to be called is determined at runtime based on the object's actual type, not the reference type declared at compile time. Runtime Polymorphism Flow Base Class Circle Rectangle ...

Read More

Size of a Three-dimensional array in C#

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

To get the size of a three-dimensional array in C#, you can use the GetLength() method to retrieve the size of individual dimensions, or the Length property to get the total number of elements across all dimensions. Syntax Following is the syntax for getting the size of specific dimensions − array.GetLength(dimensionIndex) Following is the syntax for getting the total number of elements − array.Length Parameters dimensionIndex − A zero-based integer representing the dimension index (0 for first dimension, 1 for second dimension, 2 for third dimension). ...

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

EnumerateFiles method in C#

George John
George John
Updated on 17-Mar-2026 565 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

How to List all Substrings in a given String using C#?

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

A substring is any contiguous sequence of characters within a string. In C#, you can generate all possible substrings of a given string using the Substring() method with nested loops to iterate through different starting positions and lengths. Syntax The Substring() method extracts a portion of a string − string.Substring(startIndex, length) To generate all substrings, use nested loops − for (int length = 1; length

Read More

C# Enum Equals Method

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

The Equals() method in C# is used to compare enum values for equality. It returns true if both enum values have the same underlying value, and false otherwise. Syntax Following is the syntax for using the Equals() method with enums − enumValue1.Equals(enumValue2) Parameters enumValue2 − The enum value to compare with the current enum value Return Value The method returns a bool value − true if both enum values are equal false if the enum values are different ...

Read More

File Objects in C#

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

The FileStream class in C# is used to create, read, write, and manipulate files. It provides low-level access to file operations and is part of the System.IO namespace. FileStream works with bytes, making it suitable for both text and binary files. Syntax Following is the syntax for creating a FileStream object − FileStream objectName = new FileStream(fileName, FileMode, FileAccess, FileShare); A simplified syntax for common scenarios − FileStream objectName = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite); Parameters Parameter Description Common Values fileName Path and ...

Read More

How to call Math Operations using Delegates in C#?

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

To understand how to call Math Operations using Delegates in C#, let us see an example wherein we will perform mathematical operations like division, multiplication, and addition using delegates. A delegate in C# is a type that represents references to methods with a specific signature. Syntax Following is the syntax for declaring a delegate that can reference mathematical methods − delegate returnType DelegateName(parameters); Following is the syntax for assigning methods to a delegate − DelegateName delegateInstance = MethodName; // or DelegateName delegateInstance = new DelegateName(MethodName); Using Delegates for Basic Math ...

Read More
Showing 91–100 of 789 articles
« Prev 1 8 9 10 11 12 79 Next »
Advertisements