Articles on Trending Technologies

Technical articles with clear explanations and examples

DateTime.AddYears() Method in C#

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

The DateTime.AddYears() method in C# adds a specified number of years to a DateTime instance and returns a new DateTime object. This method is particularly useful for calculating future or past dates, handling anniversaries, or working with year-based intervals. Syntax Following is the syntax for the AddYears() method − public DateTime AddYears(int value); Parameters The method accepts a single parameter − value − An integer representing the number of years to add. Use positive values to add years and negative values to subtract years. Return Value Returns a ...

Read More

What does the keyword var do in C#?

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

The var keyword in C# enables implicit type declaration where the compiler automatically determines the variable's type based on the assigned value. This feature was introduced in C# 3.0 and provides cleaner code while maintaining type safety. Syntax Following is the syntax for using var keyword − var variableName = initialValue; The compiler infers the type from the initial value. Once declared, the variable behaves as if it were declared with its actual type. How It Works When you use var, the C# compiler performs type inference at compile time. The variable ...

Read More

How to create a Directory using C#?

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

To create, move, and delete directories in C#, the System.IO.Directory class provides essential methods for directory operations. The Directory.CreateDirectory() method is used to create new directories at specified paths. Syntax Following is the syntax for creating a directory using Directory.CreateDirectory() method − Directory.CreateDirectory(string path); Following is the syntax for checking if a directory exists before creating it − if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } Parameters path − A string representing the directory path to create. Can be an absolute or relative path. ...

Read More

C# program to get max occurred character in a String

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

To find the maximum occurred character in a string in C#, we need to count the frequency of each character and then identify which character appears most frequently. This can be achieved using different approaches including character arrays and dictionaries. Syntax Using a character frequency array − int[] frequency = new int[256]; // ASCII characters for (int i = 0; i < str.Length; i++) frequency[str[i]]++; Using a dictionary for character counting − Dictionary charCount = new Dictionary(); foreach (char c in str) { charCount[c] ...

Read More

Join, Sleep and Abort methods in C# Threading

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

The Thread class in C# provides several important methods to control thread execution: Join(), Sleep(), and Abort(). These methods allow you to synchronize threads, pause execution, and terminate threads when needed. Syntax Following is the syntax for the three main thread control methods − // Join method thread.Join(); thread.Join(timeout); // Sleep method Thread.Sleep(milliseconds); // Abort method (obsolete in .NET Core/.NET 5+) thread.Abort(); Join Method The Join() method blocks the calling thread until the target thread terminates. This ensures that the calling thread waits for another thread to complete before continuing execution. ...

Read More

Delegation vs Inheritance in C#

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

In C#, both delegation and inheritance are fundamental concepts that enable code reusability and polymorphism, but they work in fundamentally different ways. Delegation uses composition and method references, while inheritance establishes an "is-a" relationship between classes. Delegation in C# A delegate is a reference type variable that holds references to methods. It enables runtime flexibility by allowing you to change method references dynamically. Delegation follows the composition principle where objects contain references to other objects. Syntax delegate Example using System; public delegate void NotificationHandler(string message); public ...

Read More

Math.Sqrt() Method in C#

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

The Math.Sqrt() method in C# is used to compute the square root of a specified number. This static method is part of the System.Math class and returns a double value representing the positive square root of the input. Syntax Following is the syntax − public static double Sqrt(double val); Parameters val − A double-precision floating-point number for which to calculate the square root. Must be greater than or equal to zero for a valid numeric result. Return Value The method returns a double value with the following behavior − ...

Read More

Variable Arguments (Varargs) in C#

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

The params keyword in C# allows a method to accept a variable number of arguments of the same type. This feature, known as variable arguments or varargs, enables you to call a method with any number of parameters without creating an array explicitly. Syntax Following is the syntax for declaring a method with variable arguments − public static returnType MethodName(params type[] parameterName) { // method body } The params keyword must be the last parameter in the method signature, and only one params parameter is allowed per method. Key Rules ...

Read More

String slicing in C# to rotate a string

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

String slicing in C# allows you to rotate characters within a string by combining substrings. This technique uses the Substring() method to extract portions of a string and rearrange them to achieve the desired rotation effect. String rotation involves moving characters from one position to another within the string. For example, rotating the first two characters of "welcome" to the end results in "lcomewe". Syntax Following is the syntax for the Substring() method − string.Substring(startIndex, length) For string rotation, combine two substrings − string rotated = str.Substring(n) + str.Substring(0, n); ...

Read More

String Formatting in C# to add padding

seetha
seetha
Updated on 17-Mar-2026 1K+ Views

String formatting with padding in C# allows you to align text in columns by adding spaces to the left or right of strings. This is particularly useful for creating formatted tables, reports, or aligned output displays. Padding is controlled by format specifiers that define the width and alignment of each placeholder in the format string. Syntax The basic syntax for padding in format strings is − string.Format("{index, width}", value) Where − index − The parameter index (0, 1, 2, etc.) width − The total width of the field Positive width − ...

Read More
Showing 11381–11390 of 61,303 articles
Advertisements