Arjun Thakur

Arjun Thakur

749 Articles Published

Articles by Arjun Thakur

Page 7 of 75

What are all the possible C# array initialization syntaxes?

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

C# provides multiple ways to initialize arrays, giving you flexibility in how you declare and populate arrays with values. Each syntax has its specific use cases depending on whether you know the array size in advance or want to provide initial values immediately. Array Initialization Syntax Options Explicit Size with Values You can specify the array size explicitly along with initial values − int[] marks = new int[5] { 99, 98, 92, 97, 95 }; Implicit Size with Values The array size can be inferred from the number of elements provided − ...

Read More

Way to increment a character in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 2K+ Views

In C#, you can increment a character by using the increment operator ++. When you increment a character, it moves to the next character in the ASCII table sequence. Syntax Following is the syntax for incrementing a character − char ch = 'K'; ch++; // moves to next ASCII character You can also use the compound assignment operator − ch += 1; // equivalent to ch++ How It Works Characters in C# are stored as numeric values based on their ASCII or Unicode code points. When you ...

Read More

Numbers in C#

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

Numbers in C# are represented by various data types, with int being the most commonly used for whole numbers. The int type represents a 32-bit signed integer that can store values from -2, 147, 483, 648 to 2, 147, 483, 647. Basic Integer Operations C# supports standard mathematical operations on integers using arithmetic operators. Here's how to perform basic addition − using System; class Program { static void Main() { int x = 20; int y = 30; ...

Read More

Semaphore in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 4K+ Views

A Semaphore in C# is a synchronization primitive that controls access to a pool of resources by allowing a specified number of threads to enter a critical section simultaneously. It maintains a count of available permits and blocks threads when the limit is reached. The System.Threading.Semaphore class provides all the methods and properties needed to implement semaphore functionality in multithreaded applications. Syntax The basic syntax for creating a semaphore − Semaphore semaphore = new Semaphore(initialCount, maximumCount); To acquire and release the semaphore − semaphore.WaitOne(); // Acquire the semaphore ...

Read More

How to convert an array of characters into a string in C#?

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

Converting an array of characters into a string is a common operation in C#. There are multiple approaches to accomplish this, each suitable for different scenarios. Syntax Following is the syntax for converting a character array to string using the string constructor − string str = new string(charArray); Following is the syntax using the string constructor with range specification − string str = new string(charArray, startIndex, length); Using String Constructor The simplest way to convert a character array to a string is using the string constructor that accepts a ...

Read More

What are integer literals in C#?

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

An integer literal in C# is a constant numeric value written directly in the code. Integer literals can be decimal (base 10) or hexadecimal (base 16) constants. A prefix specifies the base: 0x or 0X for hexadecimal, with no prefix for decimal. They can also have suffixes like U for unsigned and L for long. Syntax Following is the syntax for different types of integer literals − // Decimal literals 123 200L // long 456U // unsigned int 789UL // unsigned long // Hexadecimal literals 0xFF ...

Read More

C# Program to display the number of days in a month

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

The DateTime.DaysInMonth() method in C# is used to display the number of days in a specific month and year. This static method is particularly useful when working with calendar calculations or when you need to validate dates. Syntax Following is the syntax for using DateTime.DaysInMonth() − int days = DateTime.DaysInMonth(year, month); Parameters year: An integer representing the year (1 to 9999). month: An integer representing the month (1 to 12). Return Value Returns an integer representing the number of days in the specified month and ...

Read More

What are Booleans types in C#?

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

The bool type in C# represents Boolean values and can store only two possible values: true and false. The bool keyword is an alias for the System.Boolean structure in the .NET framework. Boolean variables are commonly used in conditional statements, loops, and logical operations to control program flow based on true/false conditions. Syntax Following is the syntax for declaring Boolean variables − bool variableName = true; // or false bool variableName; // defaults to false Basic Boolean Declaration and Assignment Example ...

Read More

try keyword in C#

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

The try keyword in C# is used to define a block of code that might throw an exception. It must be followed by one or more catch blocks to handle exceptions, and optionally a finally block for cleanup code that runs regardless of whether an exception occurs. Syntax Following is the basic syntax for a try-catch block − try { // code that might throw an exception } catch (ExceptionType e) { // exception handling code } Following is the syntax with a finally block − ...

Read More

Represent exact representation of no time in C#

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

The TimeSpan.Zero property in C# represents the exact representation of no time, which displays as 00:00:00. This is a static readonly field that provides a convenient way to initialize or compare TimeSpan values when you need to represent zero duration. Syntax Following is the syntax for using TimeSpan.Zero − TimeSpan timespan = TimeSpan.Zero; You can also use it for comparison operations − if (timespan == TimeSpan.Zero) { // timespan represents no time } Using TimeSpan.Zero for Initialization The most common use of TimeSpan.Zero is to initialize ...

Read More
Showing 61–70 of 749 articles
« Prev 1 5 6 7 8 9 75 Next »
Advertisements