Articles on Trending Technologies

Technical articles with clear explanations and examples

How to use the ?: conditional operator in C#?

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

The conditional operator (also called the ternary operator) is represented by the symbol ?:. It provides a concise way to write simple if-else statements in a single expression. The operator has right-to-left associativity and evaluates a boolean condition to return one of two possible values. Syntax Following is the syntax for the conditional operator − condition ? value_if_true : value_if_false Where: condition is an expression that evaluates to a boolean value value_if_true is returned if the condition is true value_if_false is returned if the condition is false How It Works ...

Read More

Dictionary.Count Property in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 575 Views

The Dictionary.Count property in C# gets the number of key/value pairs contained in the Dictionary. This property is read-only and provides an efficient way to determine the size of your dictionary collection. Syntax public int Count { get; } Return Value The property returns an int representing the total number of key/value pairs in the dictionary. The count is automatically updated when items are added or removed. Using Dictionary.Count Property Basic Usage Example The following example demonstrates how to use the Count property to track dictionary size − using ...

Read More

DateTime.ToShortDateString() Method in C#

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

The DateTime.ToShortDateString() method in C# is used to convert the value of the current DateTime object to its equivalent short date string representation. This method formats the date according to the current culture's short date pattern, excluding the time portion. Syntax Following is the syntax − public string ToShortDateString(); Return Value This method returns a string that represents the short date value of the current DateTime object. The format depends on the current culture's DateTimeFormatInfo.ShortDatePattern property. Using ToShortDateString() with Specific DateTime Example using System; public class Demo { ...

Read More

Boxing and Unboxing in C#

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

Boxing is the process of converting a value type to a reference type by wrapping it in an object. Unboxing is the reverse process — extracting the value type from the boxed object. These operations allow value types to be treated as objects when needed. Boxing and Unboxing Process Value Type int myVal = 12 Reference Type object myBoxed Boxing (Implicit) Unboxing (Explicit Cast) Stored on Stack ...

Read More

Command Line arguments in C#

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

Command line arguments in C# allow you to pass data to your program when it starts. These arguments are received through the string[] args parameter in the Main method, making your applications flexible and configurable from the command line. When you create a C# program, the Main method can accept command line arguments as an array of strings. Each argument passed from the command line becomes an element in this array. Syntax Following is the syntax for accepting command line arguments in the Main method − static void Main(string[] args) { // ...

Read More

What are objects in C#?

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

In C#, objects are instances of classes that represent real-world entities. An object is created from a class blueprint and contains actual data and behavior. Objects allow you to access and manipulate the members (fields, properties, and methods) defined in a class. To access class members through an object, you use the dot (.) operator. This operator connects the object name with the member name, enabling you to set values, call methods, and interact with the object's functionality. Syntax Following is the syntax for creating an object and accessing its members − ClassName objectName = ...

Read More

C# Program to set the timer to zero

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

The Stopwatch class in C# provides precise timing capabilities. To set the timer to zero, you can use the Restart() method, which stops the current timer and immediately starts it again from zero. Syntax Following is the syntax to create and start a Stopwatch − Stopwatch stopwatch = Stopwatch.StartNew(); Following is the syntax to restart the timer and set it to zero − stopwatch.Restart(); Using Restart() Method The Restart() method combines two operations: it stops the current timer and immediately starts a new timing session from zero. This is ...

Read More

C# Program to get distinct element from a sequence

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

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

Read More

Background and foreground thread in C#

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

A thread is defined as the execution path of a program. Each thread defines a unique flow of control. In C#, threads are classified as either foreground threads or background threads based on their behavior when the main application terminates. The key difference is that foreground threads keep the application alive, while background threads are automatically terminated when all foreground threads finish execution. Thread Types Comparison Foreground Thread Background Thread Keeps the application running until it completes Terminated automatically when all foreground threads end Default thread type (IsBackground ...

Read More

How to use sizeof() operator to find the size of a data type or a variable in C#

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

The sizeof operator in C# returns the size of a data type in bytes. It can only be used with value types and is particularly useful when working with unmanaged code or memory allocation scenarios. Syntax Following is the syntax for using the sizeof operator − sizeof(datatype) For example, to find the size of an int data type − sizeof(int); Key Rules The sizeof operator can only be used with value types, not reference types. It returns the size in bytes. For built-in ...

Read More
Showing 10811–10820 of 61,297 articles
Advertisements