George John

George John

789 Articles Published

Articles by George John

Page 9 of 79

C# Program to find the sum of a sequence

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

A sequence in C# is a collection of elements that can be processed using LINQ methods. To find the sum of a sequence, you can use several approaches including the Sum() method from LINQ, which provides a simple and efficient way to calculate the total. The most common approach is using the LINQ Sum() method, which can be applied to any IEnumerable collection. Syntax Following is the syntax for using the Sum() method − // For numeric collections collection.Sum(); // With selector function collection.Sum(x => x.Property); Using LINQ Sum() Method The ...

Read More

What are extender provider components in C#?

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

An extender provider in C# is a component that can extend other controls by providing additional properties to them at design time. The most common example is the ToolTip component, which adds tooltip functionality to other controls on a form. When you add a ToolTip component to a form, it automatically provides a new property (like "ToolTip on toolTip1") to every other control on the form. This allows you to set tooltip text for each control without directly modifying the control itself. How Extender Providers Work Extender providers implement the IExtenderProvider interface and use special naming conventions ...

Read More

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 897 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 159 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 463 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
Showing 81–90 of 789 articles
« Prev 1 7 8 9 10 11 79 Next »
Advertisements