Csharp Articles

Page 56 of 196

What is the difference between List and IList in C#?

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

The main difference between List and IList in C# is that List is a concrete class that implements the list functionality, while IList is an interface that defines the contract for list operations. The IList interface inherits from both ICollection and IEnumerable interfaces. List and IList both represent collections of objects that can be accessed by index. They provide methods to insert, remove, search, and sort elements. The key distinction is that List is a specific implementation while IList is a contract that multiple classes can implement. Key Differences List IList ...

Read More

What is an Optional parameter in C#?

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

By default, all parameters of a method are required. However, C# allows you to define optional parameters that do not force you to pass arguments at calling time. This means you can call a method without passing values for some parameters. Optional parameters contain default values in the function definition. If you do not pass an argument for an optional parameter at calling time, the default value is used automatically. There are different ways to make a parameter optional in C#. Syntax Following is the syntax for declaring optional parameters using default values − ...

Read More

How to make a method deprecated in C#?

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

The Obsolete Attribute marks elements like classes, methods, properties, fields, delegates, and many others within our code as deprecated or obsolete. The attribute is read at compile time and is used to generate a warning or an error to the developer. This attribute can help if we have ever wanted to make sure programmers use newer versions of methods. It also makes it easier when we are transitioning from older methods to newer ones. Marking an item as obsolete warns users that program elements will be removed in future versions of the code base. This attribute is found ...

Read More

How to update the value stored in a Dictionary in C#?

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

In C#, Dictionary is a generic collection which is generally used to store key/value pairs. In Dictionary, the key cannot be null, but value can be. A key must be unique. Duplicate keys are not allowed if we try to use duplicate key then compiler will throw an exception. As mentioned above a value in a dictionary can be updated by using its key as the key is unique for every value. Syntax Following is the syntax for updating a dictionary value − myDictionary[myKey] = myNewValue; You can also use the TryGetValue method ...

Read More

How to create Guid value in C#?

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

A Globally Unique Identifier or Guid represents a 128-bit identification number that is mathematically guaranteed to be unique across multiple systems and distributed applications. The total number of unique keys (approximately 3.40282366×10³⁸) is so large that the probability of generating the same number twice is negligible. GUIDs are commonly used in applications where unique identification is critical, such as database primary keys, transaction IDs, or session identifiers. They are typically displayed as a sequence of hexadecimal digits like 3F2504E0-4F89-11D3-9A0C-0305E82C3301. Syntax The Guid structure is present in the System namespace. Following are the most common ways to create ...

Read More

What is the difference between IEnumerable and IQueryable in C#?

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

The IEnumerable and IQueryable interfaces are both used for querying collections in C#, but they differ significantly in how they execute queries and handle data. Understanding these differences is crucial for writing efficient database queries and managing memory usage. Key Differences Feature IEnumerable IQueryable Namespace System.Collections System.Linq Query Execution In-memory (client-side) Server-side (database) Lazy Loading Not supported Supported Extension Methods Use functional objects Use expression trees Best For In-memory collections Database queries Syntax Following is the syntax for ...

Read More

What is bin and obj folder in C#?

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

Whenever we write a C# code and build or run the solution, it generates 2 folders − bin folder obj folder These folders contain compiled code at different stages of the compilation process. Understanding the difference between them is crucial for C# developers working with build systems and deployment. Why Two Folders? The compilation process in C# goes through multiple stages, which is why we have separate folders for different outputs − Compiling − Individual source files are compiled into intermediate objects Linking − All compiled objects are linked together into the ...

Read More

What is #if DEBUG and How to use it in C#?

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

In Visual Studio, Debug mode and Release mode are different configurations for building your .NET project. The #if DEBUG directive is a preprocessor conditional compilation directive that allows you to include or exclude code blocks based on whether the DEBUG symbol is defined. The Debug mode does not optimize the binary it produces because the relationship between source code and generated instructions is more complex. This allows breakpoints to be set accurately and allows programmers to step through the code one line at a time. The Debug configuration compiles with full symbolic debug information, while the Release configuration has ...

Read More

How to use order by, group by in c#?

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

The OrderBy and GroupBy operators are essential LINQ methods in C# that allow you to sort and organize data collections. OrderBy sorts sequences in ascending order, while GroupBy organizes flat sequences into groups based on a specified key. These operators are particularly useful when working with collections of objects that need to be organized or sorted for better data presentation and analysis. Syntax Following is the syntax for OrderBy operator − var result = collection.OrderBy(x => x.PropertyName); var resultDesc = collection.OrderByDescending(x => x.PropertyName); Following is the syntax for GroupBy operator − ...

Read More

What is the implicit implementation of the interface and when to use implicit implementation of the interface in C#?

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

C# interface members can be implemented in two ways: implicitly and explicitly. With implicit implementation, the implementing class doesn't include the interface name before the member name, making the compiler infer the interface connection automatically. In implicit implementation, the members are exposed as public and are accessible when the object is cast as either the concrete type or the interface type. This approach is simpler and more commonly used when there are no naming conflicts between interface methods. Syntax Following is the syntax for implicit interface implementation − interface IInterfaceName { void ...

Read More
Showing 551–560 of 1,951 articles
« Prev 1 54 55 56 57 58 196 Next »
Advertisements