C# Program to Calculate the Area of a Circle

AYUSH MISHRA
Updated on 17-Mar-2026 07:04:36

5K+ Views

A circle is a round two-dimensional shape where all points on the boundary are equidistant from the center. The distance from the center to any point on the circle's edge is called the radius. Calculating the area of a circle is a fundamental geometric operation commonly used in programming. Formula for Circle Area The area of a circle is calculated using the formula − Area = π × r² Where: π (pi) ≈ 3.14159 or Math.PI in C# r is the radius of the circle Circle ... Read More

How to get the remaining elements of the Tuple in C#?

AmitDiwan
Updated on 17-Mar-2026 07:04:36

164 Views

The Rest property in C# is used to get the remaining elements of a Tuple when it contains more than 7 elements. Since Tuple can hold a maximum of 8 elements, the 8th position (accessed via the Rest property) contains any additional elements as a nested Tuple. Syntax Following is the syntax for accessing the Rest property of a Tuple − var tuple = Tuple.Create(item1, item2, ..., item7, item8); var restElements = tuple.Rest; How It Works When a Tuple has exactly 8 elements, the Rest property returns the 8th element. When a Tuple ... Read More

Remove element at specified index of Collection in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

232 Views

To remove an element at a specified index from a Collection in C#, you use the RemoveAt() method. This method removes the element at the specified zero-based index and shifts all subsequent elements down by one position. Syntax Following is the syntax for the RemoveAt() method − collection.RemoveAt(index); Parameters index − The zero-based index of the element to remove. Must be a valid index within the collection bounds. Using RemoveAt() for Single Element Removal The following example demonstrates removing a single element at index 3 from a Collection − ... Read More

How to get the Standard Input and Output Stream through Console in C#?

AmitDiwan
Updated on 17-Mar-2026 07:04:36

474 Views

The Console class in C# provides three standard streams for input and output operations: Console.In for standard input, Console.Out for standard output, and Console.Error for standard error. These streams allow you to access the underlying TextReader and TextWriter objects used by the console. Standard Streams Overview The console streams are represented as properties that return the following types − Console.In − Returns a TextReader object for reading standard input Console.Out − Returns a TextWriter object for writing to standard output Console.Error − Returns a TextWriter object for writing to standard error ... Read More

What is the difference between Func delegate and Action delegate in C#?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

2K+ Views

A delegate is a type that represents references to methods with a particular parameter list and return type. When we instantiate a delegate, we can associate its instance with any method with a compatible signature and return type. We can invoke (or call) the method through the delegate instance. The .NET Framework provides two built-in generic delegate types: Func and Action. Both serve different purposes based on whether the method returns a value or not. Func Delegate The Func delegate is a generic delegate included in the System namespace. It has zero or more input parameters and ... Read More

Remove elements from a HashSet with conditions defined by the predicate in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

367 Views

The RemoveWhere method in C# allows you to remove elements from a HashSet based on conditions defined by a predicate function. This method takes a delegate that returns true for elements that should be removed and false for elements that should be kept. Syntax Following is the syntax for using RemoveWhere method − public int RemoveWhere(Predicate match) Parameters match − A predicate delegate that defines the conditions for removal. Returns true for elements to be removed. Return Value Returns an int representing the number of elements that were removed ... Read More

How to get TypeCode in C#?

AmitDiwan
Updated on 17-Mar-2026 07:04:36

258 Views

To get the TypeCode in C#, you use the GetTypeCode() method available on all value types and some reference types. The TypeCode is an enumeration that represents the type classification of a .NET type, providing a simplified way to identify common data types. Syntax Following is the syntax for getting TypeCode − TypeCode typeCode = value.GetTypeCode(); You can also use the static method from the Convert class − TypeCode typeCode = Type.GetTypeCode(typeof(DataType)); Return Value The GetTypeCode() method returns a TypeCode enumeration value that represents the type classification. Common TypeCode ... Read More

How to convert byte array to an object stream in C#?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

2K+ Views

A stream is an abstract base class that provides a generic view of a sequence of bytes. Streams support three fundamental operations: reading, writing, and seeking. Converting a byte array to a stream allows you to work with the data using stream-based operations and can lead to performance improvements in certain scenarios. In C#, you can convert a byte array to an object stream using the MemoryStream class, which represents a stream whose backing store is memory. Syntax Following is the syntax for converting a byte array to a MemoryStream − MemoryStream stream = new ... Read More

C# Program to Append Text to an Existing File

Ankit kumar
Updated on 17-Mar-2026 07:04:36

11K+ Views

Appending text means adding new information to the end of an existing file. In C#, we can append text to files using various methods from the System.IO namespace. This is particularly useful for logging, data collection, and maintaining records. Behavior with Non-Existing Files When attempting to append to a file that doesn't exist, C# automatically creates a new file with the specified name and then adds the content. This eliminates the need for separate file existence checks in most scenarios. Using File.AppendAllText() Method Syntax public static void AppendAllText(string path, string contents); This ... Read More

Remove elements from a SortedSet that match the predicate in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

359 Views

The RemoveWhere method in C# allows you to remove elements from a SortedSet based on a specified condition or predicate. This method evaluates each element against the predicate function and removes all elements that satisfy the condition. Syntax Following is the syntax for the RemoveWhere method − public int RemoveWhere(Predicate match) Parameters match: A Predicate delegate that defines the conditions of the elements to remove. The predicate returns true for elements that should be removed. Return Value The method returns an int representing the number of elements removed from the SortedSet. ... Read More

Advertisements