Articles on Trending Technologies

Technical articles with clear explanations and examples

How to generate the first 100 even Numbers using C#?

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

To generate the first 100 even numbers in C#, you can use a for loop and check if each number is divisible by 2. An even number has no remainder when divided by 2, which can be tested using the modulo operator (%). What are Even Numbers? Even numbers are integers that are divisible by 2 without a remainder. Examples include 2, 4, 6, 8, 10, and so on. The condition number % 2 == 0 identifies even numbers. Even Number Test Number 8 ...

Read More

What is the octal equivalent of a decimal number in C#?

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

To get the octal equivalent of a decimal number in C#, you need to repeatedly divide the decimal number by 8 and store the remainders. The octal number system uses base 8 (digits 0-7), while decimal uses base 10. Syntax Following is the basic algorithm for decimal to octal conversion − while (decimal != 0) { remainder = decimal % 8; decimal = decimal / 8; // store remainder in array } How It Works The conversion process involves dividing the decimal number by ...

Read More

Using the new keyword in C#

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

The new keyword in C# is used to create instances of objects, arrays, and collections. It allocates memory for the object and calls the appropriate constructor to initialize it. Syntax Following is the syntax for using the new keyword to create objects − ClassName objectName = new ClassName(); Following is the syntax for creating arrays using new − dataType[] arrayName = new dataType[size]; Following is the syntax for creating collections using new − CollectionType collectionName = new CollectionType(); Using 'new' to Create Objects The most ...

Read More

Get the width and height of a three-dimensional array

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

To get the width and height of a three-dimensional array in C#, we use the Array.GetLength() method. This method returns the number of elements in a specified dimension of the array. In a three-dimensional array declared as int[, , ] arr = new int[3, 4, 5], the dimensions represent different aspects of the array structure. Syntax Following is the syntax for getting dimensions of a three-dimensional array − arrayName.GetLength(dimension) Where dimension is − 0 − First dimension (rows) 1 − Second dimension (columns) 2 − Third dimension (depth) Understanding ...

Read More

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 576 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 565 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
Showing 11041–11050 of 61,297 articles
Advertisements