karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 14 of 143

C# Linq SelectMany Method

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

The SelectMany method in C# LINQ is used to flatten collections of collections into a single sequence. It projects each element of a sequence to an IEnumerable and then flattens the resulting sequences into one sequence. Syntax Following is the basic syntax for SelectMany method − public static IEnumerable SelectMany( this IEnumerable source, Func selector ) Parameters source − The input sequence to transform. selector − A function that transforms each element into a collection. Return Value Returns an IEnumerable whose ...

Read More

How is an array declared in C#?

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

To declare an array in C#, you specify the data type followed by square brackets and the array name. Arrays in C# are reference types that store multiple elements of the same data type in a contiguous memory location. Syntax Following is the basic syntax for declaring an array − datatype[] arrayName; To declare and initialize an array with a specific size − datatype[] arrayName = new datatype[size]; To declare and initialize an array with values − datatype[] arrayName = {value1, value2, value3, ...}; Here − ...

Read More

C# Generics vs C++ Templates

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

C# Generics and C++ Templates both provide support for parameterized types, allowing you to write reusable code that works with different data types. However, they differ significantly in their design philosophy, capabilities, and implementation approaches. Key Differences Between C# Generics and C++ Templates Feature C# Generics C++ Templates Compilation Model Compile-time and run-time support Compile-time only Type Safety Strong type checking at compile-time Duck typing, errors at instantiation Specialization No explicit or partial specialization Full support for specialization Non-type Parameters Not supported Fully supported ...

Read More

How to use XmlSerializer in C#?

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

The XmlSerializer in C# is used to convert objects to XML format (serialization) and back to objects (deserialization). This allows you to store object data in XML files or transmit data between applications in a standardized XML format. XmlSerializer provides fine-grained control over how objects are encoded into XML, including element names, attributes, and namespaces through various attributes. Syntax Following is the syntax for creating an XmlSerializer instance − XmlSerializer serializer = new XmlSerializer(typeof(ClassName)); Following is the syntax for serializing an object to XML − using (StreamWriter writer = new StreamWriter(filePath)) ...

Read More

C# Single() Method

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

The Single() method in C# returns the only element of a sequence. It throws an exception if the sequence is empty or contains more than one element, making it useful when you expect exactly one element. The Single() method is available in both LINQ to Objects and LINQ to Entities through the System.Linq namespace. Syntax Following is the syntax for the Single() method − public static TSource Single(this IEnumerable source); public static TSource Single(this IEnumerable source, Func predicate); Parameters source − The IEnumerable to return the single element from. predicate − ...

Read More

C# Multiple Local Variable Declarations

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

In C#, you can declare and initialize multiple local variables of the same type in a single statement using the comma operator. This provides a concise way to declare several variables at once, making your code more readable and reducing repetition. Syntax Following is the syntax for declaring multiple local variables of the same type − dataType variable1 = value1, variable2 = value2, variable3 = value3; You can also declare variables without initialization − dataType variable1, variable2, variable3; Basic Multiple Variable Declaration The following example demonstrates declaring four integer ...

Read More

What is the maximum possible value of an integer in C# ?

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

The maximum possible value of a 32-bit signed integer (int) in C# is 2, 147, 483, 647. This value is also available through the constant int.MaxValue. However, C# provides several integer types with different ranges and maximum values. Integer Types and Their Maximum Values C# offers multiple integer data types, each with different storage sizes and value ranges − Type Size Range Maximum Value sbyte 8-bit signed -128 to 127 127 byte 8-bit unsigned 0 to 255 255 short 16-bit signed -32, 768 to 32, 767 ...

Read More

Try/catch/finally/throw keywords in C#

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

Exception handling in C# is implemented using four key keywords that work together to manage runtime errors gracefully. The try block contains code that might throw an exception, catch blocks handle specific exceptions, finally executes cleanup code regardless of whether an exception occurs, and throw is used to raise exceptions manually. Syntax Following is the basic syntax for exception handling in C# − try { // code that might throw an exception } catch (SpecificExceptionType ex) { // handle specific exception } catch (Exception ex) { // ...

Read More

ToDictionary method in C#

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

The ToDictionary method is a LINQ extension method in C# that converts any collection into a Dictionary. It allows you to specify how to extract the key and value from each element in the source collection. Syntax Following is the basic syntax for the ToDictionary method − source.ToDictionary(keySelector) source.ToDictionary(keySelector, valueSelector) source.ToDictionary(keySelector, valueSelector, comparer) Parameters keySelector − A function to extract the key from each element. valueSelector − A function to extract the value from each element (optional). comparer − An equality comparer to compare keys (optional). ...

Read More

C# Program to check if a number is prime or not

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

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. To check if a number is prime in C#, we need to verify that it has exactly two divisors. Algorithm To determine if a number is prime, we use a for loop to check all numbers from 1 to the given number. We count how many divisors exist by checking if the remainder is zero when dividing the number by each potential divisor − for (int i = 1; i

Read More
Showing 131–140 of 1,421 articles
« Prev 1 12 13 14 15 16 143 Next »
Advertisements