George John

George John

789 Articles Published

Articles by George John

Page 8 of 79

Transpose a matrix in C#

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

Transpose of a matrix flips the matrix over its diagonal, swapping rows and columns. This operation converts the element at position [i][j] to position [j][i] in the transposed matrix. For example − Matrix before Transpose: 1 2 3 4 5 6 7 8 9 Matrix after Transpose: 1 4 7 2 5 8 3 6 9 Matrix Transpose Operation Original Matrix 1 2 3 4 5 6 7 8 9 rows columns ...

Read More

ArgumentNullException in C#

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

The ArgumentNullException is thrown when a null reference is passed to a method that does not accept it as a valid argument. This exception is part of the System namespace and helps prevent null reference errors by catching them early. This exception commonly occurs when methods expect non-null parameters but receive null values instead. It provides clear error messages indicating which parameter was null. Syntax Following is the syntax for throwing ArgumentNullException − throw new ArgumentNullException(paramName); throw new ArgumentNullException(paramName, "Custom message"); Following is the syntax for handling ArgumentNullException − try { ...

Read More

Tuple.Create method in C#

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

The Tuple.Create method in C# is a convenient way to create tuple objects without explicitly specifying their types. The method automatically infers the types from the provided arguments, making tuple creation more concise and readable. Syntax Following is the syntax for using Tuple.Create method − var tupleName = Tuple.Create(item1, item2, ...); The method can accept up to 8 parameters of different types − Tuple.Create(T1 item1); Tuple.Create(T1 item1, T2 item2); // ... up to 8 items Creating Basic Tuples Example Here we create a tuple with a string and ...

Read More

C# Average Method

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

The Average() method in C# calculates the arithmetic mean of a sequence of numeric values. This method is part of LINQ (Language Integrated Query) and can be used with arrays, lists, and other enumerable collections. The Average() method has multiple overloads to work with different numeric types including int, double, decimal, float, and their nullable counterparts. Syntax Following is the basic syntax for the Average() method − public static double Average(this IEnumerable source) public static double Average(this IEnumerable source) public static decimal Average(this IEnumerable source) Parameters source − An enumerable ...

Read More

What is the difference between Read(), ReadKey() and ReadLine() methods in C#?

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

The Console class in C# provides three different methods for reading user input: Read(), ReadKey(), and ReadLine(). Each method serves a specific purpose and returns different types of data from the standard input stream. Syntax Following are the syntaxes for the three input methods − int result = Console.Read(); // Returns ASCII value ConsoleKeyInfo keyInfo = Console.ReadKey(); // Returns key information string input = Console.ReadLine(); // Returns string Console.Read() Method The Read() method reads the next character from the ...

Read More

What are the differences between class methods and class members in C#?

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

In C#, understanding the difference between class members and class methods is fundamental to object-oriented programming. Class members are the data components that store the state of an object, while class methods are the functions that operate on that data and define the object's behavior. Class Members vs Class Methods Class Members Class Methods Store data and represent the state of an object Define behavior and operations on the object's data Examples: fields, properties, constants Examples: functions, procedures, constructors Hold values that can change over time Execute ...

Read More

What are two-dimensional arrays in C#?

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

A two-dimensional array in C# is an array of arrays, where elements are arranged in rows and columns like a table or matrix. It stores data in a grid format with two indices: one for the row and one for the column. Two-dimensional arrays are useful for representing tabular data, matrices, game boards, or any data structure that requires a grid-like organization. Syntax Following is the syntax for declaring a two-dimensional array − datatype[, ] arrayName = new datatype[rows, columns]; Following is the syntax for initializing a two-dimensional array with values − ...

Read More

C# Decimal ("D") Format Specifier

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

The "D" (decimal) format specifier in C# is used to format integer types as a string of decimal digits (0-9). It displays the number with optional zero-padding to achieve a specified minimum length. Syntax Following is the syntax for the "D" format specifier − number.ToString("D") // Basic decimal format number.ToString("Dn") // Decimal with minimum n digits Where n is the minimum number of digits. If the number has fewer digits, it will be padded with leading zeros. Parameters ...

Read More

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 445 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
Showing 71–80 of 789 articles
« Prev 1 6 7 8 9 10 79 Next »
Advertisements