Programming Articles

Page 838 of 2547

DateTime.ToShortTimeString() Method in C#

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

The DateTime.ToShortTimeString() method in C# converts a DateTime object to its equivalent short time string representation. This method formats the time portion of the date using the current system culture's short time pattern, typically showing hours and minutes in 12-hour or 24-hour format. Syntax Following is the syntax − public string ToShortTimeString(); Return Value Returns a string that contains the short time string representation of the current DateTime object. Using ToShortTimeString() with Current DateTime This example demonstrates how to use ToShortTimeString() with the current system time and shows the culture-specific formatting ...

Read More

Transpose a matrix in C#

George John
George John
Updated on 17-Mar-2026 3K+ Views

Transpose of a matrix flips the matrix over its diagonal, swapping rows and columns. This operation converts the element at position [i][j] to position [j][i] in the transposed matrix. For example − Matrix before Transpose: 1 2 3 4 5 6 7 8 9 Matrix after Transpose: 1 4 7 2 5 8 3 6 9 Matrix Transpose Operation Original Matrix 1 2 3 4 5 6 7 8 9 rows columns ...

Read More

Different ways for Integer to String Conversions in C#

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

Converting integers to strings is a common operation in C# programming. There are several built-in methods available, each with different use cases and performance characteristics. Syntax Following are the main syntaxes for integer to string conversion − // Using ToString() method string str = number.ToString(); // Using Convert.ToString() method string str = Convert.ToString(number); // Using string interpolation string str = $"{number}"; // Using string.Format() method string str = string.Format("{0}", number); Using ToString() Method The ToString() method is the most commonly used approach for converting integers to strings. It's called directly ...

Read More

Get bounds of a C# three-dimensional array

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

To get the bounds of a three-dimensional array in C#, use the GetUpperBound() and GetLowerBound() methods. These methods return the highest and lowest indices for a specified dimension of the array. The parameter passed to these methods specifies the dimension (0, 1, or 2 for a three-dimensional array). Understanding array bounds is crucial for safe array traversal and avoiding index out-of-range exceptions. Syntax Following is the syntax for getting array bounds − array.GetUpperBound(dimension) array.GetLowerBound(dimension) Parameters dimension: An integer specifying the dimension of the array (0-based indexing). Return ...

Read More

DateTime.ToString() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 563 Views

The DateTime.ToString() method in C# converts a DateTime object to its string representation. This method provides multiple overloads to format the date and time according to different requirements using format strings and culture-specific formatting. Syntax The DateTime.ToString() method has four overloads − ToString() ToString(String) ToString(IFormatProvider) ToString(String, IFormatProvider) Parameters format − A standard or custom date and time format string. provider − An object that supplies culture-specific formatting information. Return Value Returns a string representation of the current DateTime object formatted according to the specified format string and culture information. ...

Read More

The Object Class in C#

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

The Object class is the base class of all classes in C# and the .NET Framework. Every class in C# implicitly inherits from the Object class, which means all objects have access to the fundamental methods provided by this base class. When you create any class in C#, it automatically inherits from Object even if you don't explicitly specify it. This provides a common set of methods that every object can use. Syntax Every class implicitly inherits from Object − public class MyClass { // This class inherits from Object automatically } ...

Read More

C# Program to display a string in reverse alphabetic order

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 893 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 898 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
Showing 8371–8380 of 25,466 articles
« Prev 1 836 837 838 839 840 2547 Next »
Advertisements