Ankith Reddy

Ankith Reddy

730 Articles Published

Articles by Ankith Reddy

Page 9 of 73

C# Program to generate random lowercase letter

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 2K+ Views

In C#, you can generate a random lowercase letter using the Random class and ASCII character conversion. This technique generates a random number between 0 and 25, then converts it to a corresponding lowercase letter from 'a' to 'z'. Syntax Following is the syntax for generating a random lowercase letter − Random random = new Random(); int randomIndex = random.Next(0, 26); char randomLetter = (char)('a' + randomIndex); How It Works The process involves three key steps: Generate random number: random.Next(0, 26) produces a number from 0 to 25 ...

Read More

C# Program to find a key in Dictionary

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

In C#, a Dictionary is a collection that stores key-value pairs. To check if a specific key exists in a Dictionary, you can use the ContainsKey() method, which returns true if the key is found and false otherwise. Syntax Following is the syntax for using the ContainsKey() method − bool result = dictionary.ContainsKey(key); Parameters key − The key to locate in the Dictionary. Return Value Returns true if the Dictionary contains an element with the specified key; otherwise, false. Using ContainsKey() Method The most straightforward way to ...

Read More

What are the difference between Composition and Aggregation in C#?

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

Composition and Aggregation are two important types of associations in C# that represent different levels of dependency between classes. Understanding these relationships helps design better object-oriented systems with proper coupling and lifecycle management. Composition Composition represents a strong "part-of" relationship where the child object cannot exist independently of the parent object. When the parent is destroyed, all child objects are also destroyed automatically. Composition: Strong Ownership Car (Owner) Engine (Owned) ...

Read More

How to join two lists in C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 6K+ Views

To join two lists in C#, you can use several methods. The most common approaches are using the AddRange() method to modify an existing list, or using LINQ's Concat() method to create a new combined list without modifying the originals. Syntax Using AddRange() to modify the first list − list1.AddRange(list2); Using LINQ Concat() to create a new list − var combinedList = list1.Concat(list2).ToList(); Using AddRange() Method The AddRange() method adds all elements from the second list to the end of the first list, modifying the original list − ...

Read More

Func generic type in C#

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

The Func generic type in C# is a built-in delegate that represents a method which takes zero or more input parameters and returns a value. It provides a convenient way to store anonymous methods, lambda expressions, and regular methods that return a value. Syntax Following is the syntax for declaring a Func delegate − Func funcName; // No parameters, returns TResult Func funcName; ...

Read More

Convert.ToUInt64 Method in C#

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

The Convert.ToUInt64() method in C# converts a specified value to a 64-bit unsigned integer (ulong). This method accepts various data types and returns their equivalent ulong representation. Syntax Following is the syntax for the Convert.ToUInt64() method − public static ulong ToUInt64(object value) public static ulong ToUInt64(string value) public static ulong ToUInt64(char value) public static ulong ToUInt64(int value) public static ulong ToUInt64(double value) Parameters value − The value to convert. Can be of type object, string, char, numeric types, or other convertible types. Return Value Returns a 64-bit ...

Read More

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

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

The Array.Length property in C# is used to get the total number of elements in an array. This property returns an integer value representing the array's size, which is essential for array manipulation and iteration. Syntax Following is the syntax for using the Array.Length property − int length = arrayName.Length; Return Value The Length property returns an int value representing the total number of elements in the array. Using Array.Length with Array.CreateInstance The following example demonstrates how to use Array.Length with dynamically created arrays − using System; class ...

Read More

How to truncate a file in C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 1K+ Views

To truncate a file in C#, use the FileStream.SetLength method. This method allows you to change the size of a file by either reducing it (truncating) or expanding it to a specified length. Syntax Following is the syntax for the SetLength method − public override void SetLength(long value); Parameters value − A long representing the desired length of the stream in bytes. How It Works The behavior of SetLength depends on whether the new value is smaller or larger than the current file size − ...

Read More

C# Program to access tuple elements

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

In C#, tuples are data structures that can hold multiple values of different types. Once you create a tuple, you can access its elements using the Item properties, where each element is numbered starting from Item1. Syntax Following is the syntax for creating a tuple using Tuple.Create() − var tupleName = Tuple.Create(value1, value2, value3, ...); Following is the syntax for accessing tuple elements − tupleName.Item1 // First element tupleName.Item2 // Second element tupleName.Item3 // Third element Using Item Properties to Access Elements Create a tuple with ...

Read More

C# object serialization

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

Object serialization in C# is the process of converting an object into a stream of bytes for storage or transmission. The serialized data can be saved to files, databases, or sent over a network, and later deserialized back into objects. C# provides several approaches for serialization, including binary serialization, XML serialization, and JSON serialization. Binary serialization preserves the complete object state and type information. Syntax For binary serialization using BinaryFormatter − [Serializable] public class ClassName { // class members } BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, objectInstance); For deserialization ...

Read More
Showing 81–90 of 730 articles
« Prev 1 7 8 9 10 11 73 Next »
Advertisements