karthikeya Boyini

karthikeya Boyini

1,420 Articles Published

Articles by karthikeya Boyini

Page 26 of 142

What is a sealed class in C#?

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

A sealed class in C# is a class that cannot be inherited by other classes. When you declare a class as sealed, it prevents any other class from deriving from it. The sealed keyword can also be applied to methods to prevent them from being overridden in further derived classes. Sealed classes are useful when you want to restrict inheritance for security, performance, or design reasons. Common examples include the string class and many value types in .NET Framework. Syntax Following is the syntax for declaring a sealed class − public sealed class ClassName { ...

Read More

Convert.ToUInt32 Method in C#

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

The Convert.ToUInt32 method in C# converts a specified value to a 32-bit unsigned integer (uint). This method can convert various data types including strings, integers, floating-point numbers, and other numeric types to an unsigned 32-bit integer. The uint data type can hold values from 0 to 4, 294, 967, 295, making it suitable for scenarios where you need positive integers only with a larger range than regular int. Syntax Following are the common overloads of the Convert.ToUInt32 method − Convert.ToUInt32(string value) Convert.ToUInt32(int value) Convert.ToUInt32(double value) Convert.ToUInt32(object value) Parameters value − The ...

Read More

C# program to find the sum of digits of a number using Recursion

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

A recursive function calls itself with modified parameters until it reaches a base case. To find the sum of digits of a number using recursion, we extract the last digit using the modulus operator (%) and add it to the sum of remaining digits. Syntax Following is the syntax for a recursive function to sum digits − public int SumOfDigits(int number) { if (number == 0) { return 0; // base case } return (number % 10) + SumOfDigits(number / ...

Read More

What does Array.LongLength property of array class do in C#?

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

The Array.LongLength property in C# gets a 64-bit integer (long) that represents the total number of elements in all dimensions of an array. This property is particularly useful when working with very large arrays that might exceed the range of a 32-bit integer. Syntax Following is the syntax for using the LongLength property − long totalElements = arrayName.LongLength; Return Value The property returns a long value representing the total number of elements across all dimensions of the array. Single-Dimensional Array Example For a single-dimensional array, LongLength returns the same value as ...

Read More

Compare two strings lexicographically in C#

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

The String.Compare() method in C# performs lexicographic (alphabetical) comparison between two strings. It compares strings character by character based on their Unicode values and is case-sensitive by default. Syntax Following is the syntax for the basic String.Compare() method − int result = string.Compare(string1, string2); For case-insensitive comparison − int result = string.Compare(string1, string2, true); Return Value The String.Compare() method returns an integer value indicating the lexicographic relationship between the two strings − If str1 is less than str2, it returns -1. If str1 is equal to str2, ...

Read More

Understanding IndexOutOfRangeException Exception in C#

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

The IndexOutOfRangeException is a common runtime exception in C# that occurs when you attempt to access an array element using an index that is outside the valid range of indices for that array. This exception helps prevent memory corruption by catching invalid array access attempts. Arrays in C# are zero-indexed, meaning the first element is at index 0, and the last element is at index length - 1. Attempting to access an index less than 0 or greater than or equal to the array length will throw this exception. When IndexOutOfRangeException Occurs This exception is thrown in ...

Read More

Does declaring an array create an array in C#?

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

Declaring an array in C# does not create the actual array object in memory. Array declaration only creates a reference variable that can point to an array object. The array must be explicitly initialized using the new keyword to allocate memory and create the array instance. Array Declaration vs Array Creation Understanding the difference between declaration and creation is crucial for working with arrays in C# − Array Declaration vs Creation Declaration Only int[] arr; • Creates reference variable • No memory ...

Read More

What is a managed code in C#?

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

Managed code in C# is code whose execution is managed by the Common Language Runtime (CLR). The CLR provides automatic memory management, type safety, exception handling, and garbage collection. When you write C# code, it gets compiled into Intermediate Language (IL) code, which is then executed by the CLR. Unlike unmanaged code (such as C/C++), managed code runs within the .NET runtime environment, which handles low-level operations automatically. This makes development safer and more efficient by reducing common programming errors like memory leaks and buffer overflows. How Managed Code Works The execution process of managed code follows ...

Read More

Local Inner Class in C#

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

A nested class in C# is a class declared inside another enclosing class. The nested class is a member of its outer class and can access the outer class's private members, while the outer class cannot directly access the nested class's members without creating an instance. Nested classes provide better organization and encapsulation by grouping related functionality together. They are particularly useful when a class is only meaningful within the context of another class. Syntax Following is the syntax for declaring a nested class − class OuterClass { // outer class ...

Read More

How to iterate two Lists or Arrays with one foreach statement in C#?

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

When working with multiple collections in C#, you often need to iterate through them simultaneously. The Zip() method from LINQ provides an elegant solution to combine two arrays or lists and iterate them with a single foreach statement. Syntax Following is the syntax for using the Zip() method to combine two collections − var result = collection1.Zip(collection2, (item1, item2) => new { Prop1 = item1, Prop2 = item2 }); The lambda expression defines how to combine elements from both collections into a new anonymous object. Using Zip() with Arrays The Zip() method ...

Read More
Showing 251–260 of 1,420 articles
« Prev 1 24 25 26 27 28 142 Next »
Advertisements