Programming Articles

Page 815 of 2547

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 513 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 349 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 927 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 461 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

Static vs. Non-Static method in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 1K+ Views

In C#, methods can be declared as either static or non-static (instance methods). Static methods belong to the class itself and can be called without creating an instance of the class, while non-static methods belong to specific instances of the class. Static methods can only access static variables and other static members directly. They exist even before any object of the class is created and are shared across all instances of the class. Syntax Following is the syntax for declaring a static method − public static returnType MethodName() { // method ...

Read More

C# Program to get the difference between two dates

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

The DateTime.Subtract() method in C# is used to calculate the difference between two dates. It returns a TimeSpan object representing the time interval between the two dates. Syntax Following is the syntax for using DateTime.Subtract() method − TimeSpan result = dateTime1.Subtract(dateTime2); Alternatively, you can use the subtraction operator − TimeSpan result = dateTime1 - dateTime2; Parameters The Subtract() takes one parameter − value − A DateTime object to subtract from the current instance. Return Value Returns a TimeSpan object that represents the difference between ...

Read More
Showing 8141–8150 of 25,466 articles
« Prev 1 813 814 815 816 817 2547 Next »
Advertisements