
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2587 Articles for Csharp

185 Views
Local functions are private methods of a type that are nested in another member. They can only be called from their containing member.Local functions can be declared in and called from −Methods, especially iterator methods and async methodsConstructorsProperty accessorsEvent accessorsAnonymous methodsLambda expressionsFinalizersOther local functionsExample 1class Program{ public static void Main(){ void addTwoNumbers(int a, int b){ System.Console.WriteLine(a + b); } addTwoNumbers(1, 2); Console.ReadLine(); } }Output3Example 2class Program{ public static void Main(){ void addTwoNumbers(int a, int b, out int c){ c = a + b; } addTwoNumbers(1, 2, out int c); System.Console.WriteLine(c); Console.ReadLine(); } }Output3

202 Views
C# allows to use multiple deconstructor methods in the same program with the same number of out parameters or the same number and type of out parameters in a different order.It's a part of the new tuple syntax - which has nothing to do with the Tuple classes but is taking from functional programming.Deconstruct keyword is used for DeconstructorsExamplepublic class Employee{ public Employee(string employeename, string firstName, string lastName){ Employeename = employeename; FirstName = firstName; LastName = lastName; } public string Employeename { get; } public string FirstName ... Read More

204 Views
We can declare out values inline as arguments to the method where they're used.The existing out parameters has been improved in this version. Now we can declare out variables in the argument list of a method call, rather than writing a separate declaration statement.Advantages −The code is easier to read.No need to assign an initial value.Existing Syntax −Exampleclass Program{ public static void AddMultiplyValues(int a, int b, out int c, out int d){ c = a + b; d = a * b; } public static void Main(){ int ... Read More

462 Views
Switch is a selection statement that chooses a single switch section to execute from a list of candidates based on a pattern match with the match expression.The switch statement is often used as an alternative to an if-else construct if a single expression is tested against three or more conditions.Switch statement is quicker. The switch statement the average number of comparisons will be one regardless of how many different cases you have So lookup of an arbitrary case is O(1)Using Switch −Exampleclass Program{ public enum Fruits { Red, Green, Blue } public static void Main(){ Fruits c = (Fruits)(new Random()).Next(0, ... Read More

2K+ Views
No, anonymous types cannot implement an interface. We need to create your own type.Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first.The type name is generated by the compiler and is not available at the source code level. The type of each property is inferred by the compiler.You create anonymous types by using the new operator together with an object initializer.Exampleclass Program{ public static void Main(){ var v = new { Amount = 108, Message = "Test" }; ... Read More

1K+ Views
Retry logic is implemented whenever there is a failing operation. Implement retry logic only where the full context of a failing operation.It's important to log all connectivity failures that cause a retry so that underlying problems with the application, services, or resources can be identified.Exampleclass Program{ public static void Main(){ HttpClient client = new HttpClient(); dynamic res = null; var retryAttempts = 3; var delay = TimeSpan.FromSeconds(2); RetryHelper.Retry(retryAttempts, delay, () =>{ res = client.GetAsync("https://example22.com/api/cycles/1"); }); ... Read More

2K+ Views
Both Monitor and lock provides a mechanism that synchronizes access to objects. lock is the shortcut for Monitor.Enter with try and finally.Lock is a shortcut and it's the option for the basic usage. If we need more control to implement advanced multithreading solutions using TryEnter() Wait(), Pulse(), & PulseAll() methods, then the Montior class is your option.Example for Lock −Exampleclass Program{ static object _lock = new object(); static int Total; public static void Main(){ AddOneHundredLock(); Console.ReadLine(); } public static void AddOneHundredLock(){ for (int i = 1; i

583 Views
Overloads of the Sort() method in List class expects Comparison delegate to be passed as an argument.public void Sort(Comparison comparison)CompareTo returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object or the other Int16 instance.The Int16.CompareTo() method in C# is used to compare this instance to a specified object or another Int16 instanceExampleclass Program{ public static void Main(){ Employee Employee1 = new Employee(){ ID = 101, Name = "Mark", ... Read More

10K+ Views
Inner join returns only those records or rows that match or exists in both the tables. We can also apply to join on multiple tables based on conditions as shown below. Make use of anonymous types if we need to apply to join on multiple conditions.In the below example we have written 2 ways that can be used to join in Linq Here the Department and the Employee are joinedExampleclass Program{ static void Main(string[] args){ var result = Employee.GetAllEmployees().Join(Department.GetAllDepartments(), e => e.DepartmentID, d => d.ID, (employee, department) ... Read More

2K+ Views
In Visual Studio Debug mode and Release mode are different configurations for building your .Net project.Select the Debug mode for debugging step by step their .Net project and select the Release mode for the final build of Assembly file (.dll or .exe).To change the build configuration −From the Build menu, select Configuration Manager, then select Debug or Release. Or On the toolbar, choose either Debug or Release from the Solution Configurations list.The code which is written inside the #if debug will be executed only if the code is running inside the debug mode.If the code is running in the release ... Read More