Programming Articles

Page 835 of 2547

C# Program to convert first character uppercase in a sentence

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

Converting the first character of each word to uppercase in a sentence is a common text formatting task in C#. This process involves identifying word boundaries and converting the first lowercase letter of each word to its uppercase equivalent. Syntax Following is the basic approach to convert characters from lowercase to uppercase − char uppercaseChar = (char)(lowercaseChar - 'a' + 'A'); To check if a character is a lowercase letter − if (ch >= 'a' && ch = 'a' && val[i] = 'A' && val[i] word.Length > 0 ? ...

Read More

What are sealed modifiers in C#?

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

The sealed modifier in C# prevents method overriding in derived classes. When applied to an overridden method, it stops further inheritance of that method. The sealed method must be part of a derived class and must override a virtual or abstract method from its base class. Syntax Following is the syntax for declaring a sealed method − public sealed override ReturnType MethodName() { // method implementation } Key Rules for Sealed Methods A sealed method must be an override of a virtual or abstract method. Once ...

Read More

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

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 947 Views

To generate the first 100 odd numbers in C#, you can use different approaches. The most straightforward method is to iterate through numbers and check if they are odd using the modulus operator. Syntax Following is the syntax for checking if a number is odd − if (number % 2 != 0) { // number is odd } Following is the syntax for generating odd numbers in a loop − for (int i = 1; i

Read More

ElementAt() method in C#

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

The ElementAt() method in C# is a LINQ extension method that retrieves an element at a specified index from any collection that implements IEnumerable. It provides a way to access elements by index in collections that don't have built-in indexing support. Syntax Following is the syntax for the ElementAt() method − public static TSource ElementAt(this IEnumerable source, int index) Parameters source − The IEnumerable to return an element from. index − The zero-based index of the element to retrieve. Return Value Returns the element at the specified position in ...

Read More

C# Program to order array elements in descending order

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

To order array elements in descending order in C#, you can use various approaches including Array.Sort() with reversal, LINQ's OrderByDescending(), or custom comparison methods. These methods provide flexibility for sorting different data types and applying custom sorting criteria. Syntax Following is the syntax for basic descending sort using Array.Sort() and Array.Reverse() − Array.Sort(arrayName); Array.Reverse(arrayName); Following is the syntax for LINQ OrderByDescending() − var result = array.OrderByDescending(element => element); Using Array.Sort() and Array.Reverse() The simplest approach is to sort the array in ascending order first, then reverse it − ...

Read More

Boolean.Parse() Method in C#

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

The Boolean.Parse() method in C# is used to convert the specified string representation of a logical value to its Boolean equivalent. This method converts strings like "true", "false", "TRUE", or "FALSE" to their corresponding boolean values. Syntax Following is the syntax − public static bool Parse(string value); Parameters value − A string containing the value to convert. It can be "true", "false", "True", "False", "TRUE", or "FALSE". Return Value Returns true if the value is equivalent to TrueString, or false if the value is equivalent to FalseString. Using ...

Read More

How to call a method of a class in C#

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

To call a method of a class in C#, you need to create an instance of the class first, then use the dot notation to access its methods. The general syntax is objectName.MethodName(parameters). Syntax Following is the syntax for calling an instance method − ClassName objectName = new ClassName(); returnType result = objectName.MethodName(parameters); For static methods, you call them directly on the class without creating an instance − returnType result = ClassName.StaticMethodName(parameters); Using Instance Methods Instance methods require an object of the class to be called. Here's how you ...

Read More

What are static or fixed length arrays in C#?

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

A static array or fixed-length array in C# is a data structure with a predetermined size that cannot be changed after creation. Once you declare an array with a specific length, that size remains constant throughout the program's execution. Static arrays are different from dynamic collections like List because their size is immutable. This makes them memory-efficient and provides predictable performance characteristics. Syntax Following is the syntax for declaring a static array − dataType[] arrayName = new dataType[size]; You can also initialize a static array with values at declaration − dataType[] ...

Read More

What is the difference between Write() and WriteLine() methods in C#?

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

The difference between Write() and WriteLine() methods in C# is based on the new line character. Both methods are used to display output to the console, but they handle line termination differently. Write() method displays the output but does not provide a new line character, so subsequent output appears on the same line. WriteLine() method displays the output and automatically adds a new line character at the end, moving the cursor to the next line for subsequent output. Syntax Following is the syntax for Write() method − Console.Write(value); Console.Write("text"); Following is the syntax ...

Read More

C# Linq ThenBy Method

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

The ThenBy() method in C# LINQ is used to perform a secondary sort on a sequence that has already been ordered using OrderBy(). It allows you to sort by multiple criteria, where OrderBy() defines the primary sort and ThenBy() defines the secondary sort for elements that are equal in the primary sort. Syntax Following is the syntax for using ThenBy() method − IEnumerable result = source.OrderBy(keySelector1).ThenBy(keySelector2); You can chain multiple ThenBy() methods for additional sort levels − IEnumerable result = source.OrderBy(key1).ThenBy(key2).ThenBy(key3); Parameters keySelector − A function that ...

Read More
Showing 8341–8350 of 25,466 articles
« Prev 1 833 834 835 836 837 2547 Next »
Advertisements