Articles on Trending Technologies

Technical articles with clear explanations and examples

Math.Min() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 3K+ Views

The Math.Min() method in C# is used to return the smaller of two specified numbers. This method is overloaded to work with various numeric data types including byte, decimal, double, float, int, long, sbyte, short, uint, ulong, and ushort. Syntax Following are the most commonly used overloads − public static int Min(int val1, int val2); public static double Min(double val1, double val2); public static decimal Min(decimal val1, decimal val2); public static float Min(float val1, float val2); public static long Min(long val1, long val2); public static byte Min(byte val1, byte val2); public static short Min(short val1, short ...

Read More

Value Type vs Reference Type in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 8K+ Views

Value type and reference type are two fundamental categories of data types in C#. Understanding their differences is crucial for memory management and program behavior. Value types store data directly, while reference types store a reference to the memory location where the data is stored. Syntax Following is the syntax for declaring value type variables − int number = 10; char letter = 'A'; bool flag = true; Following is the syntax for declaring reference type variables − string text = "Hello"; object obj = new object(); int[] array = new int[5]; ...

Read More

How to print a line on the console using C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 816 Views

To display a line on the console in C#, we use the Console.WriteLine() method. This method prints text to the console and automatically adds a new line at the end. Syntax Following is the syntax for printing a line to the console − Console.WriteLine(value); Where value can be a string, variable, or any expression that can be converted to a string. Using Console.WriteLine() with Strings The most common use is to print string literals or string variables − using System; public class Program { public static ...

Read More

Union Method in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 972 Views

The Union method in C# is a LINQ extension method that returns the unique elements from both collections. It combines two sequences and automatically removes duplicate values, ensuring each element appears only once in the result. Syntax Following is the syntax for the Union method − public static IEnumerable Union( this IEnumerable first, IEnumerable second ) Parameters first − The first sequence to merge. second − The second sequence to merge. Return Value Returns an IEnumerable containing ...

Read More

C# Queryable LongCount Method

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 230 Views

The LongCount() method in C# is part of the System.Linq namespace and returns the number of elements in a sequence as a long data type. This method is particularly useful when dealing with large collections where the count might exceed the range of an int (2, 147, 483, 647). The LongCount() x % 2 == 0); Console.WriteLine("Even numbers: {0}", evenCount); long greaterThanFive = numbers.AsQueryable().LongCount(x => x > 5); ...

Read More

Math.Pow() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 6K+ Views

The Math.Pow() method in C# is used to compute a number raised to the power of another number. It returns the result as a double value and can handle both positive and negative bases and exponents. Syntax Following is the syntax − public static double Pow(double val1, double val2) Parameters val1 − A double-precision floating-point number to be raised to a power (the base). val2 − A double-precision floating-point number that specifies the power (the exponent). Return Value Returns a double representing val1 raised to ...

Read More

How to declare a two-dimensional array in C#

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

A two-dimensional array in C# is a data structure that stores elements in a grid-like format with rows and columns. It can be thought of as an array of arrays, where each element is accessed using two indices. Syntax Following is the syntax for declaring a two-dimensional array − datatype[, ] arrayName; Following is the syntax for initializing a two-dimensional array − datatype[, ] arrayName = new datatype[rows, columns]; You can also declare and initialize in one statement − datatype[, ] arrayName = new datatype[rows, columns] { ...

Read More

How to print multiple blank lines in C#?

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

In C#, there are several ways to print multiple blank lines to the console. You can use loops, string repetition, or direct method calls depending on your needs. Using a While Loop The most straightforward approach is to use a while loop to print blank lines repeatedly − using System; namespace Program { public class Demo { public static void Main(string[] args) { int a = 0; while ...

Read More

Why is f required while declaring floats in C#?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 875 Views

The f suffix is required when declaring float literals in C# because without it, the compiler treats decimal numbers as double by default. The f suffix explicitly tells the compiler that the literal should be treated as a float type. Why the 'f' Suffix is Needed In C#, numeric literals with decimal points are interpreted as double precision floating-point numbers by default. Since double has higher precision than float, implicit conversion from double to float is not allowed because it could result in data loss. Literal Type Assignment ...

Read More

Difference between Static Constructor and Instance Constructor in C#

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

In C#, constructors are special methods used to initialize objects. There are two main types: static constructors and instance constructors. Understanding their differences is crucial for proper class initialization and memory management. Static Constructor A static constructor is declared using the static modifier and is responsible for initializing static members of a class. It executes only once during the application lifetime, before any static members are accessed or any instances are created. Syntax static ClassName() { // initialize static members } Instance Constructor An instance constructor initializes instance ...

Read More
Showing 11371–11380 of 61,303 articles
Advertisements