Csharp Articles

Page 112 of 196

StringWriter vs StringReader in C#?

George John
George John
Updated on 17-Mar-2026 464 Views

StringReader and StringWriter are classes in C# that derive from TextReader and TextWriter respectively. They provide convenient ways to read from and write to strings as if they were streams or files. StringWriter is used for writing data into a string buffer, while StringReader is used for reading data from a string. Both classes are particularly useful when working with APIs that expect TextReader or TextWriter objects. StringWriter Class StringWriter implements a TextWriter for writing information to a string. It maintains an internal StringBuilder that accumulates the written content. Syntax StringWriter writer = new ...

Read More

What is the difference between String and string in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 663 Views

In C#, string and String are functionally identical − string is simply an alias for System.String. Both refer to the same .NET type and can be used interchangeably in your code. Syntax Both declarations are equivalent − string str1 = "Hello World"; String str2 = "Hello World"; Both can use static methods from the String class − string result1 = string.Format("Hello {0}", name); string result2 = String.Format("Hello {0}", name); Key Differences string (lowercase) String (uppercase) C# keyword and alias Actual .NET class ...

Read More

Write a C# program to find GCD and LCM?

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

In C#, finding the GCD (Greatest Common Divisor) and LCM (Least Common Multiple) of two numbers is a common mathematical programming task. The GCD is the largest positive integer that divides both numbers without remainder, while the LCM is the smallest positive integer that both numbers can divide evenly. These calculations are frequently used in mathematical applications, fraction simplification, and solving problems involving ratios and proportions. Mathematical Relationship There's an important mathematical relationship between GCD and LCM − GCD(a, b) × LCM(a, b) = a × b This means once we find the ...

Read More

What is the difference between String.Copy() and String.CopyTo() methods in C#?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 405 Views

The String.Copy() and String.CopyTo() methods in C# serve different purposes for copying string data. String.Copy() creates a new string object with the same content, while String.CopyTo() copies characters from a string into a character array. Syntax Following is the syntax for String.Copy() method − public static string Copy(string str) Following is the syntax for String.CopyTo() method − public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count) Parameters String.Copy() Parameters: str − The string to copy. String.CopyTo() Parameters: sourceIndex − The index of ...

Read More

What is method hiding in C#?

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

Method hiding (also known as shadowing) in C# occurs when a derived class defines a method with the same name as a method in its base class, but without using the override keyword. The child class creates its own version of the method that hides the parent class method rather than overriding it. Method hiding uses the new keyword to explicitly indicate that the method is intended to hide the base class method. This is different from method overriding, which uses override and creates polymorphic behavior. Syntax Following is the syntax for method hiding using the new ...

Read More

What is static binding in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 1K+ Views

Static binding in C# refers to the process of linking a function call to its implementation at compile time. This is also known as early binding or compile-time polymorphism. The compiler determines which method to call based on the method signature and the types of arguments passed. C# provides two main techniques to implement static binding through static polymorphism − Function Overloading − Multiple methods with the same name but different parameters Operator Overloading − Custom implementations for operators like +, -, *, etc. Static Binding Process ...

Read More

What is the difference between a mutable and immutable string in C#?

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

In C#, mutable strings can be modified after creation, while immutable strings cannot be changed once created. The StringBuilder class represents mutable strings, whereas the string class represents immutable strings. When you modify an immutable string, .NET creates a new string object in memory. With mutable strings using StringBuilder, modifications are made to the existing object without creating new memory allocations. Immutable String A string in C# is immutable, meaning once created, it cannot be modified. Any operation that appears to modify a string actually creates a new string object in memory. Syntax string ...

Read More

What is the difference between an interface and an abstract class in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 684 Views

In C#, both interfaces and abstract classes provide a way to define contracts that derived classes must follow. However, they serve different purposes and have distinct characteristics that make them suitable for different scenarios. An interface defines a contract specifying what methods, properties, and events a class must implement, but provides no implementation itself. An abstract class can provide both abstract members (without implementation) and concrete members (with full implementation). Interface Syntax Following is the syntax for declaring an interface − public interface IInterfaceName { void MethodName(); string PropertyName ...

Read More

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

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

What is the difference between Write() and WriteLine() methods in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 6K+ Views

The difference between Write() and WriteLine() methods in C# is based on the new line character. Both methods are used to display output to the console, but they handle line termination differently. Write() method displays the output but does not provide a new line character, so subsequent output appears on the same line. WriteLine() method displays the output and automatically adds a new line character at the end, moving the cursor to the next line for subsequent output. Syntax Following is the syntax for Write() method − Console.Write(value); Console.Write("text"); Following is the syntax ...

Read More
Showing 1111–1120 of 1,951 articles
« Prev 1 110 111 112 113 114 196 Next »
Advertisements