Chandu yadav

Chandu yadav

810 Articles Published

Articles by Chandu yadav

Page 10 of 81

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

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 939 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

C# Linq LastorDefault Method

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

The LastOrDefault() method in C# LINQ returns the last element of a sequence, or a default value if the sequence is empty. This method prevents exceptions that would occur with Last() when called on empty collections. Syntax Following is the syntax for LastOrDefault() method − public static T LastOrDefault(this IEnumerable source); public static T LastOrDefault(this IEnumerable source, Func predicate); Parameters source − The sequence to return the last element from. predicate − A function to test each element for a condition (optional). Return Value Returns the last element that ...

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

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 a Byte value to an Int32 value

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

To convert a byte value to an int value in C#, you can use the Convert.ToInt32() method or implicit conversion. Since a byte (8-bit unsigned integer) can always fit within an int (32-bit signed integer), the conversion is straightforward and safe. An Int32 represents a 32-bit signed integer that can store values from -2, 147, 483, 648 to 2, 147, 483, 647, while a byte stores values from 0 to 255. Syntax Using Convert.ToInt32() method − int result = Convert.ToInt32(byteValue); Using implicit conversion − int result = byteValue; Using ...

Read More

What are contextual keywords in C#?

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

In C#, contextual keywords are special identifiers that have reserved meaning only in specific contexts. Unlike regular keywords, they can still be used as variable names or identifiers when not in their special context. Common examples include get and set in properties, where in LINQ queries, and partial in class definitions. Contextual keywords provide flexibility by allowing the same word to serve as both a keyword and an identifier depending on the context in which it appears. Syntax Contextual keywords are used within their specific contexts. Here are some common patterns − // Property accessors ...

Read More

What are the hidden features of C#?

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

C# contains several powerful but often overlooked features that can significantly improve code readability, safety, and efficiency. These hidden gems can make your C# programming more elegant and productive when used appropriately. Lambda Expressions A lambda expression is a concise way to write anonymous functions using the => operator (called the "goes to" operator). Lambda expressions are commonly used with LINQ operations and delegate assignments. Syntax (parameters) => expression (parameters) => { statements; } Example using System; using System.Linq; class Program { public static void Main() ...

Read More

Set 6-item tuple in C#'

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

A 6-item tuple in C# is a data structure that can hold six values of different or same data types. Tuples are useful when you need to return multiple values from a method or group related data together without creating a separate class. Syntax Following is the syntax for creating a 6-item tuple using the Tuple class − var tuple = new Tuple(item1, item2, item3, item4, item5, item6); Alternatively, you can use the modern tuple syntax with parentheses − var tuple = (item1, item2, item3, item4, item5, item6); Using Traditional ...

Read More

Inbuilt Data Structures in C#

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

C# provides several powerful built-in data structures that make it easier to store, organize, and manipulate collections of data. These data structures are part of the .NET Framework and offer different capabilities for various programming scenarios. The most commonly used built-in data structures include List for dynamic arrays, ArrayList for non-generic collections, Dictionary for key-value pairs, and Queue and Stack for specialized ordering operations. List The generic List is a strongly-typed collection that can dynamically resize itself. Unlike arrays, you don't need to specify the size at compile time, and it provides better type safety compared to ...

Read More

C# Linq Contains Method

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

The Contains() method in LINQ is used to check whether a sequence contains a specific element. It returns true if the element is found, otherwise false. This method works with any IEnumerable collection including arrays, lists, and queryable sequences. Syntax Following is the syntax for using Contains() with collections − bool result = collection.Contains(element); Following is the syntax for using Contains() with queryable sequences − bool result = collection.AsQueryable().Contains(element); Parameters element − The value to locate in the sequence. Return Value Returns true if the ...

Read More
Showing 91–100 of 810 articles
« Prev 1 8 9 10 11 12 81 Next »
Advertisements