Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 787 of 2109
What is a non-static class in C#?
A non-static class in C# is a regular class that can be instantiated using the new keyword. Unlike static classes, non-static classes allow you to create multiple objects (instances) and can contain both instance members and static members. Non-static classes are the default type of class in C# and form the foundation of object-oriented programming, enabling encapsulation, inheritance, and polymorphism. Syntax Following is the syntax for declaring a non-static class − public class ClassName { // instance fields // static fields // instance ...
Read MoreWhat are virtual functions in C#?
The virtual keyword in C# allows a method, property, indexer, or event to be overridden in derived classes. Virtual functions enable runtime polymorphism, where the actual method called is determined at runtime based on the object's type, not the reference type. When you define a virtual function in a base class, derived classes can provide their own implementations using the override keyword. This allows different derived classes to implement the same method differently while maintaining a common interface. Syntax Following is the syntax for declaring a virtual method − public virtual returnType MethodName() { ...
Read MoreStringWriter vs StringReader in C#?
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 MoreWhat is the difference between String and string in C#?
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 MoreWrite a C# program to find GCD and LCM?
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 MoreWhat is the difference between String.Copy() and String.CopyTo() methods in C#?
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 MoreWhat is method hiding in C#?
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 MoreWhat is static binding in C#?
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 MoreWhat is the difference between a mutable and immutable string in C#?
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 MoreWhat is the difference between an interface and an abstract class in C#?
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