Csharp Articles

Page 54 of 196

Executing C# code in Linux

Ajay yadav
Ajay yadav
Updated on 17-Mar-2026 6K+ Views

The .NET ecosystem was traditionally limited to Windows, but Microsoft's introduction of Mono changed this landscape. Mono enables the execution of .NET applications on Linux systems, making them run as if they were native Linux packages rather than Windows executable files. What is Mono? Mono is an open-source, cross-platform implementation of Microsoft's .NET Framework. It allows developers to run .NET applications on various platforms including Linux and macOS. Mono provides a complete development stack that supports Windows Forms, LINQ, XML web services, ADO.NET, and ASP.NET using the same CLR namespaces. Cross-Platform .NET with ...

Read More

Difference between Method Overriding and Method Hiding in C#

Nitin Sharma
Nitin Sharma
Updated on 17-Mar-2026 3K+ Views

In C#, there are two mechanisms for redefining or providing new implementation of a method from a parent class in its child class: Method Overriding and Method Hiding. Understanding the difference between these concepts is crucial for implementing proper inheritance and polymorphism. Method overriding uses the override keyword and enables runtime polymorphism, while method hiding uses the new keyword and provides compile-time method resolution. Syntax Following is the syntax for method overriding − public class BaseClass { public virtual void Method() { } } public class DerivedClass : BaseClass { ...

Read More

What if we are not sure of the type of value that we want to store in a variable. How to handle this in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 135 Views

As C# is a strongly-typed language, every variable and constant has a pre-defined type. Before using any variable, we must tell the compiler what type of value a variable will store. If we are not sure about the type, then it is handled using dynamic programming. Dynamic programming is supported by the dynamic keyword, which allows variables to bypass compile-time type checking and have their types resolved at runtime. Syntax Following is the syntax for declaring a dynamic variable − dynamic variableName = value; The type of the variable is determined at runtime ...

Read More

What is the use of "is" keyword in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 439 Views

The is keyword in C# is used to check if an object is of a specific type or can be cast to that type. It returns a Boolean value — true if the object is compatible with the specified type, false otherwise. The is keyword is particularly useful for type checking before performing type conversions, ensuring safe downcasting in inheritance hierarchies, and working with polymorphic objects. Syntax Following is the syntax for using the is keyword − object is Type The is keyword can also be used with pattern matching (C# 7.0+) − ...

Read More

How to store n number of lists of different types in a single generic list in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 860 Views

We can store n number of lists of different types in a single generic list by creating a list of List. This approach allows us to store lists containing integers, strings, or any other data type within a single container. Syntax Following is the syntax for creating a list that can hold multiple lists of different types − List containerList = new List(); Each inner list can store objects of any type − List innerList = new List(); innerList.Add(value); // value can be int, string, etc. containerList.Add(innerList); Using List of ...

Read More

What is the difference between int and Int32 in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 6K+ Views

Int32 is a type provided by .NET framework whereas int is an alias for Int32 in C# language. Both represent 32-bit signed integers and compile to identical code, making them functionally equivalent at runtime. Syntax Following is the syntax for declaring integers using both approaches − Int32 variable1 = value; int variable2 = value; Key Differences Aspect int Int32 Type C# language keyword (alias) .NET Framework type Namespace dependency No namespace required Requires System namespace Compilation Compiles to System.Int32 Direct .NET type ...

Read More

What does the two question marks together (??) mean in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 3K+ Views

The null-coalescing operator (??) in C# returns the value of its left-hand operand if it isn't null; otherwise, it evaluates and returns the right-hand operand. This operator provides a concise way to handle null values and assign default values. The ?? operator is particularly useful with nullable types, which can represent either a value from the type's domain or be undefined (null). It helps prevent InvalidOperationException exceptions and reduces the need for verbose null-checking code. Syntax Following is the syntax for the null-coalescing operator − result = leftOperand ?? rightOperand; If leftOperand is ...

Read More

What is @ in front of a string in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 14K+ Views

The @ symbol in front of a string in C# creates a verbatim string literal. This special prefix tells the compiler to treat the string exactly as written, ignoring escape sequences and preserving formatting including line breaks. In C#, a verbatim string is created using the @ symbol as a prefix before the opening quote. The compiler identifies this as a verbatim string and processes it literally. The main advantage of the @ symbol is to tell the string constructor to ignore escape characters and preserve line breaks exactly as they appear in the source code. Syntax ...

Read More

Which is better System.String or System.Text.StringBuilder classes in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 2K+ Views

The main difference between System.String and System.Text.StringBuilder is that StringBuilder is mutable whereas String is immutable. String is immutable, meaning once you create a string object, you cannot modify it. Any operation that appears to change a string actually creates a new string object in memory. On the other hand, StringBuilder is mutable. When you create a StringBuilder object, you can perform operations like insert, replace, or append without creating a new instance each time. It updates the string content in the same memory location. Memory Allocation Comparison String vs StringBuilder Memory ...

Read More

Why cannot we specify access modifiers inside an interface in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 975 Views

Interface members in C# traditionally cannot have access modifiers because interfaces define a contract that implementing classes must follow. The purpose of an interface is to specify what methods or properties a class must provide to the outside world, making all interface members implicitly public. Prior to C# 8.0, adding any access modifier to interface members would result in a compiler error. However, C# 8.0 introduced default interface methods, which allow access modifiers for specific scenarios involving method implementations within interfaces. Why Interface Members Are Public by Default Interfaces serve as contracts that define what functionality a ...

Read More
Showing 531–540 of 1,951 articles
« Prev 1 52 53 54 55 56 196 Next »
Advertisements