Skip to content

Latest commit

 

History

History
38 lines (24 loc) · 1.6 KB

README.md

File metadata and controls

38 lines (24 loc) · 1.6 KB

awesome-csharp

Code snippets about the lesser known features of c-sharp

This repository is generally for me to learn or revise features of C#. I am happy to share these code snippets and I hope it is useful for others.

1. String.Join: String.Join makes it easier to join elements of an array together in a string and we don't need to write a loop

2. String Interpolation: This technique makes us write more readable to embed variables in a string without using String.Format or concatenations.

3. Ref vs out: Difference between ref and out is that a variable used as out need not be initialized before usage.

4. Anonymous functions: Functions in just a single line of code.

5. HashSet: A useful collection

6. List comprehensions: Can we do in C# what we do in python?

7. Finding common elements between arrays in one line using LINQ: The power of LINQ lets us reduce several lines of code into one single line

8. Converting string to 32 bit integer: Different ways to convert a string to integer and how to avoid exceptions.

9. Different ways to declare and initialize variables (this is in a different file InitializingVariables.cs): The methods in the class visually show different coding techniques to initialize different types of variables

Instructions to run:

You can clone this repo and run the project using Visual Studio. Since this is a console application, you can directly run and view the output in the console.

Unless mentioned otherwise, code is present in Program.cs. Comments present in the code, provide further explanation.