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
Articles by Nizamuddin Siddiqui
Page 19 of 196
What are Deconstructors in C# 7.0?
Deconstructors in C# 7.0 are methods that allow you to extract multiple values from an object into separate variables in a single assignment. They enable tuple-like deconstruction of custom types, making it easier to work with objects that contain multiple related values. A deconstructor is defined using the Deconstruct method name with out parameters. When you use tuple syntax on the left side of an assignment, C# automatically calls the appropriate Deconstruct method. Syntax Following is the syntax for defining a deconstructor method − public void Deconstruct(out Type1 param1, out Type2 param2, out Type3 param3) ...
Read MoreHow to use order by, group by in c#?
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 MoreWhat are Local functions in C# 7.0?
Local functions are private methods defined inside another member (method, constructor, or property). They are only accessible within their containing member and provide a clean way to break down complex logic into smaller, reusable pieces without exposing helper methods to the entire class. Local functions were introduced in C# 7.0 and offer better performance than lambda expressions for recursive scenarios and provide compile-time checking for definite assignment. Syntax Following is the syntax for declaring a local function − returnType LocalFunctionName(parameters) { // function body } Local functions can be ...
Read MoreWhat is the implicit implementation of the interface and when to use implicit implementation of the interface in C#?
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 MoreHow to use ViewBag in ASP .Net MVC C#?
ViewBag uses the dynamic feature that was introduced in C# 4.0. It allows an object to have properties dynamically added to it. Internally, it is a dynamic type property of the ControllerBase class which is the base class of the Controller class. ViewBag only transfers data from controller to view, not vice-versa. ViewBag values will be null if redirection occurs. ViewBag is able to set and get value dynamically and able to add any number of additional fields without converting it to strongly typed. Syntax Following is the syntax for storing data in ViewBag − ...
Read MoreWhat are binary literals and digit separators in C# 7.0?
C# 7.0 introduced two important enhancements to numeric literals that improve code readability and provide new ways to represent numbers: binary literals and digit separators. These features make it easier to work with binary values and large numbers in your code. Binary Literals Before C# 7.0, you could only assign decimal and hexadecimal values to variables. Binary literals allow you to directly assign binary values using the 0b or 0B prefix, making it easier to work with bit flags, masks, and other binary operations. Syntax var binaryNumber = 0b10101010; // Binary literal var binaryNumber2 ...
Read MoreWhat is the significance of NonActionAttribute in ASP .Net MVC C#?
The NonAction attribute in ASP.NET MVC is used to prevent public methods in a controller from being treated as action methods. By default, all public methods in an MVC controller are accessible via URL routing. The NonAction attribute allows you to keep methods public (for internal use within the controller or class hierarchy) while blocking direct HTTP access. Syntax Following is the syntax for applying the NonAction attribute − [NonAction] public ReturnType MethodName() { // method implementation } Why Use NonAction Attribute In ASP.NET MVC, the framework automatically treats ...
Read MoreWhat are Ref locals and Ref returns in C# 7.0?
C# 7.0 introduced ref locals and ref returns, which allow methods to return references to variables instead of copies of their values. This enables direct modification of the original data through the returned reference. A ref return allows a method to return a reference to a variable, and the caller can create a ref local variable that directly references the returned memory location. Syntax Following is the syntax for declaring a ref return method − public static ref ReturnType MethodName(parameters) { return ref variable; } Following is the syntax ...
Read MoreWhat are the three segments of the default route, that is present in ASP .Net MVCnC#?
The ASP.NET MVC Routing module is responsible for mapping incoming browser requests to particular MVC controller actions. When the ASP.NET MVC application launches, it registers one or more patterns with the framework's route table to tell the routing engine what to do with any requests that match those patterns. When the routing engine receives a request at runtime, it matches that request's URL against the URL patterns registered with it and gives the response according to a pattern match. ASP.NET introduced Routing to eliminate the need of mapping each URL with a physical file. Routing enables us to define ...
Read MoreWhat are the levels at which filters can be applied in ASP .Net MVC C#?
In an ASP.NET MVC application, filters can be applied at three different levels to control the behavior of controllers and action methods. These levels determine the scope of filter application, from specific methods to the entire application. Action Method Level − Applies only to a specific action method Controller Level − Applies to all action methods within a controller Global Level − Applies to all controllers and action methods in the application Filter Application Levels Global Level Controller Level ...
Read More