Programming Articles

Page 874 of 2547

How to demonstrate Prefix Operator using C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 323 Views

The prefix operator in C# is used to increment or decrement a variable's value before using it in an expression. The prefix increment operator ++ increases the value by 1, while the prefix decrement operator -- decreases the value by 1. The key characteristic is that the operation happens before the variable's value is returned or used. Syntax Following is the syntax for prefix increment and decrement operators − ++variable; // Prefix increment --variable; // Prefix decrement The operators can also be used in expressions − result = ++a; ...

Read More

How to create a Dictionary using C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 296 Views

A Dictionary in C# is a collection of key-value pairs where each key is unique. The Dictionary class is part of the System.Collections.Generic namespace and provides fast lookups based on keys. Dictionaries are useful when you need to associate values with unique identifiers, such as storing employee IDs with names or product codes with prices. Syntax Following is the syntax for creating a Dictionary − Dictionary dictionaryName = new Dictionary(); Following is the syntax for adding items to a Dictionary − dictionaryName.Add(key, value); dictionaryName[key] = value; // Alternative syntax ...

Read More

How to print a diamond using nested loop using C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 467 Views

A diamond pattern is a common programming exercise that demonstrates the use of nested loops in C#. The diamond shape consists of two parts: an upper triangle that expands and a lower triangle that contracts. To create a diamond pattern, you need to consider three key elements − Number of rows (determines diamond size) Characters to display (commonly $ or *) Leading spaces for alignment Diamond Pattern Structure Upper Triangle Row 1: 4 spaces + 1 char Row 2: 3 spaces + ...

Read More

C# Linq Distinct() Method

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

The Distinct() method in C# LINQ is used to remove duplicate elements from a collection and return only unique elements. This method is available for any collection that implements IEnumerable and preserves the order of first occurrence. Syntax Following is the basic syntax for the Distinct() method − IEnumerable Distinct() IEnumerable Distinct(IEqualityComparer comparer) Parameters comparer (optional) − An IEqualityComparer to compare elements for equality. If not provided, the default equality comparer is used. Return Value Returns an IEnumerable containing distinct elements from the source sequence. Using ...

Read More

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 834 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 978 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 234 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
Showing 8731–8740 of 25,466 articles
« Prev 1 872 873 874 875 876 2547 Next »
Advertisements