Articles on Trending Technologies

Technical articles with clear explanations and examples

C# Program to display a string in reverse alphabetic order

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

To display a string in reverse order, you can convert the string to a character array and then use the Array.Reverse() method. This approach reverses the order of characters, displaying them from last to first. Syntax Following is the syntax for converting a string to character array − char[] arr = str.ToCharArray(); Following is the syntax for reversing the array − Array.Reverse(arr); Using Array.Reverse() Method The simplest approach is to convert the string to a character array and use Array.Reverse() to reverse the order of characters − ...

Read More

ArgumentNullException in C#

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

The ArgumentNullException is thrown when a null reference is passed to a method that does not accept it as a valid argument. This exception is part of the System namespace and helps prevent null reference errors by catching them early. This exception commonly occurs when methods expect non-null parameters but receive null values instead. It provides clear error messages indicating which parameter was null. Syntax Following is the syntax for throwing ArgumentNullException − throw new ArgumentNullException(paramName); throw new ArgumentNullException(paramName, "Custom message"); Following is the syntax for handling ArgumentNullException − try { ...

Read More

How do I sort a two-dimensional array in C#

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

Sorting a two-dimensional array in C# can be accomplished using several approaches. The most common methods include sorting individual rows using nested loops with bubble sort, using Array.Sort() for jagged arrays, or converting to a one-dimensional array for sorting. Syntax For sorting rows in a 2D array using nested loops − for (int i = 0; i < arr.GetLength(0); i++) { for (int j = 0; j < arr.GetLength(1) - 1; j++) { for (int k = 0; k < arr.GetLength(1) - j - 1; k++) { ...

Read More

DateTime.ToUniversalTime() Method in C#

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

The DateTime.ToUniversalTime() method in C# is used to convert the value of the current DateTime object to Coordinated Universal Time (UTC). This method is essential when working with applications that handle multiple time zones or need to store timestamps in a universal format. Syntax Following is the syntax − public DateTime ToUniversalTime(); Return Value Returns a DateTime object whose value is equivalent to the current DateTime object converted to UTC. If the current DateTime object represents a local time, it is converted to UTC using the system's time zone information. If it already ...

Read More

What is Type safe in C#?

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

Type safety in C# is a fundamental feature that prevents objects from accessing memory locations that don't belong to them. This means you cannot accidentally treat one object type as another incompatible type, which helps prevent runtime errors and memory corruption. The C# compiler enforces type safety at compile time, ensuring that operations are performed only on compatible types. This prevents common programming errors like accessing invalid memory locations or calling methods that don't exist on an object. How Type Safety Works C# prevents unsafe type conversions through compile-time checking. When you attempt to cast an object ...

Read More

C# Program to split a string on spaces

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

In C#, the Split() method is used to divide a string into an array of substrings based on a specified delimiter. When splitting a string on spaces, we use the space character ' ' as the delimiter. Syntax Following is the syntax for splitting a string on spaces − string[] result = str.Split(' '); You can also use the overloaded version with options − string[] result = str.Split(' ', StringSplitOptions.RemoveEmptyEntries); Parameters separator − The character used to split the string (space character ' ' in this case). ...

Read More

C# Program to convert an Int32 value to a decimal

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

To convert an Int32 value to a decimal in C#, you can use the Convert.ToDecimal() method or implicit casting. An Int32 represents a 32-bit signed integer, while decimal provides higher precision for financial and monetary calculations. Syntax Following is the syntax for converting Int32 to decimal using Convert.ToDecimal() − decimal result = Convert.ToDecimal(intValue); Following is the syntax for implicit casting − decimal result = intValue; Using Convert.ToDecimal() Method The Convert.ToDecimal() method explicitly converts an Int32 value to a decimal type − using System; public class Demo ...

Read More

UInt16.CompareTo() Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 236 Views

The UInt16.CompareTo() method in C# is used to compare the current instance to a specified object or UInt16 and returns an indication of their relative values. This method is essential for sorting operations and conditional comparisons involving unsigned 16-bit integers. Syntax The UInt16.CompareTo() method has two overloads − public int CompareTo(object val); public int CompareTo(ushort val); Parameters val − In the first overload, it is an object to compare. In the second overload, it is an unsigned 16-bit integer to compare. Return Value The method returns an ...

Read More

Boolean.TryParse() Method in C#

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

The Boolean.TryParse() method in C# safely converts a string representation of a logical value to its Boolean equivalent. Unlike Boolean.Parse(), this method returns true if the conversion succeeds and false if it fails, without throwing exceptions. Syntax Following is the syntax − public static bool TryParse(string value, out bool result); Parameters value − A string containing the value to convert. result − When this method returns, contains the Boolean value equivalent to the value contained in value, if the conversion succeeded, or false if the conversion failed. ...

Read More

What is the difference between declaration and definition in C#?

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

In C#, declaration means specifying the type and name of a variable, method, or class without providing an initial value or implementation. Definition (or initialization) means providing an actual value or implementation to what was declared. This distinction applies to variables, arrays, methods, and classes. Understanding the difference helps write cleaner code and avoid compilation errors. Syntax Following is the syntax for declaration − datatype variableName; Following is the syntax for definition/initialization − variableName = value; // or combined declaration and initialization datatype variableName = value; Variable Declaration vs ...

Read More
Showing 11051–11060 of 61,297 articles
Advertisements