Articles on Trending Technologies

Technical articles with clear explanations and examples

How to use ReadKey() method of Console class in C#?

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

The Console.ReadKey() method in C# reads the next character or function key pressed by the user. This method is commonly used to pause program execution until the user presses a key, which is particularly useful when running console applications from Visual Studio to prevent the console window from closing immediately. Syntax The Console.ReadKey() method has two overloads − public static ConsoleKeyInfo ReadKey(); public static ConsoleKeyInfo ReadKey(bool intercept); Parameters intercept (optional): A boolean value that determines whether to display the pressed key in the console. If true, the key is not displayed; if ...

Read More

Default value of StringBuilder in C#

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

The default operator in C# returns the default value for any data type. For reference types like StringBuilder, the default value is null. This is useful when you need to initialize a StringBuilder variable without creating an instance immediately. Syntax Following is the syntax for using the default operator with StringBuilder − StringBuilder variable = default(StringBuilder); In C# 7.1 and later, you can also use the simplified syntax − StringBuilder variable = default; Using default(StringBuilder) Example using System; using System.Text; public class Demo { ...

Read More

Implicit conversion from Char to Decimal in C#

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

In C#, implicit conversion from char to decimal happens automatically when you assign a character value to a decimal variable. The character is converted to its corresponding ASCII or Unicode numeric value, which is then stored as a decimal number. Syntax Following is the syntax for implicit conversion from char to decimal − char c = 'character'; decimal dec = c; // implicit conversion How It Works When you assign a char to a decimal, C# automatically converts the character to its numeric ASCII/Unicode value. For example, the character 'A' has an ...

Read More

Write a C# program to check if a number is prime or not

Samual Sam
Samual Sam
Updated on 17-Mar-2026 4K+ Views

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. To check if a number is prime in C#, we count how many divisors it has by iterating through all numbers from 1 to the number itself. The basic approach uses a counter that increments each time we find a divisor. If the counter equals 2 at the end (divisible only by 1 and itself), the number is prime. Algorithm The algorithm for checking prime numbers follows these steps − Initialize a counter to 0 ...

Read More

Integer literals vs Floating point literals in C#

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

In C#, literals are fixed values written directly in the source code. There are two main categories of numeric literals: integer literals for whole numbers and floating-point literals for decimal numbers. Understanding the difference between these literals is essential for proper variable declaration and avoiding compilation errors. Integer Literals An integer literal represents a whole number without a decimal point. Integer literals can be decimal (base 10) or hexadecimal (base 16). A prefix specifies the base: 0x or 0X for hexadecimal, with no prefix for decimal. Syntax decimal_literal // 10, 100, ...

Read More

final, finally and finalize in C#

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

In C#, the terms final, finally, and finalize serve different purposes. While final doesn't exist in C#, finally and finalize are crucial concepts for exception handling and resource cleanup respectively. final (sealed in C#) C# does not have a final keyword like Java. Instead, C# uses the sealed keyword to achieve similar functionality − public sealed class SealedClass { // cannot be inherited } public override sealed void SealedMethod() { // cannot be overridden further } The sealed keyword prevents overriding of methods or inheritance of classes. ...

Read More

Find free disk space using C#

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

The DriveInfo class in C# provides information about drives and their storage capacity. You can use this class to find free disk space, total disk space, and calculate the percentage of available space on any drive. Syntax Following is the syntax for creating a DriveInfo instance − DriveInfo driveInfo = new DriveInfo("driveLetter"); Following are the key properties for disk space information − long availableSpace = driveInfo.AvailableFreeSpace; long totalSpace = driveInfo.TotalSize; long usedSpace = driveInfo.TotalSize - driveInfo.AvailableFreeSpace; Using DriveInfo to Get Free Disk Space Example using System; using ...

Read More

Default value of bool in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 2K+ Views

The default operator in C# returns the default value for any data type. For the bool type, the default value is false. When a bool variable is declared without initialization, it automatically gets assigned the default value of false. Syntax Following is the syntax for using the default operator with bool − bool variable = default(bool); In C# 7.1 and later, you can also use the simplified syntax − bool variable = default; Using default(bool) Operator The following example demonstrates how to get the default value of bool ...

Read More

Dictionary.ContainsValue() Method in C#

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

The Dictionary.ContainsValue() method in C# is used to check whether the Dictionary contains a specific value or not. This method returns true if the value is found in the dictionary, otherwise it returns false. Syntax public bool ContainsValue(TValue val); Parameters val − The value to search for in the dictionary. This parameter can be null if the value type allows null values. Return Value Returns true if the dictionary contains the specified value; otherwise, false. Using ContainsValue() with Found Value The following example demonstrates checking for a value that exists ...

Read More

UInt32.ToString() Method in C# with Examples

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

The UInt32.ToString() method in C# is used to convert the numeric value of a UInt32 instance to its equivalent string representation. This method is particularly useful when you need to display unsigned 32-bit integer values as text or concatenate them with strings. The UInt32 type represents unsigned 32-bit integers with values ranging from 0 to 4, 294, 967, 295. The ToString() method provides several overloads to format the output according to different requirements. Syntax Following are the main syntax variations of the UInt32.ToString() method − public override string ToString(); public string ToString(string format); public string ...

Read More
Showing 10571–10580 of 61,297 articles
Advertisements