---
description: Programming Language designed by Anders Hejlsberg.
---

# C\#

{% embed url="https://dotnet.microsoft.com/en-us/languages/csharp" %}

&#x20;The parentheses are known as the _method invocation operator._

### Datatypes/Literals

* **string** - for words, phrases, or any alphanumeric data enclosed by double-quotes.
* **char** - for a single alphanumeric character enclosed by single quotes.
* **int** - for a numeric whole number.
* **decimal** - for a number with decimal values and _**m/M**_ as a literal suffix.
* **bool** - for a true/false boolean values.

```csharp
Console.WriteLine("Hello, World!");    //string

Console.WriteLine('a');                //char

Console.WriteLine(123);                //int

Console.WriteLine(123.456m);            //decimal
Console.WriteLine(123.456M);                    

Console.WriteLine(true);                //bool
Console.WriteLine(false);
```

{% hint style="info" %}
**Note**

**string** and **char** are only used for presentation, not for calculation.
{% endhint %}

### Variables

* Variables are temporary values you store in the computer's memory.
* Before you can use a variable, you have to declare it.
* To declare a variable, you first select a data type for the kind of data you want to store and then give the variable a name that follows the rules.

```csharp
bool processedCustomer;
char userOption;
decimal particlesPerMillion;
int gameScore;
string firstName;
```

* You must assign (set) a value to a variable before you can retrieve (get) a value from a variable.
* You can initialize a variable by assigning a value to the variable at the point of declaration.
* Assignment happens from right to left.
* You use a single equals character as the assignment operator.

&#x20;An implicitly typed local variable is created using the **`var`** keyword. The **`var`** keyword tells the compiler to infer the data type of the variable based on the value it is initialized to.

```csharp
var message = "Hello world!";
```

{% hint style="info" %}
**Note**

You can only use the **`var`** keyword if the variable is initialized.
{% endhint %}

{% hint style="info" %}
An string/character **escape sequence** is a special instruction to the runtime that you want to insert a special character that will affect the output of your string.

* `\u` - add encoded characters in literal strings, then a four-character code representing some character in Unicode (UTF-16).

`Console.WriteLine("\u3053\u3093\u306B\u3061\u306F World!");`

Output: `こんにちは World!`
{% endhint %}

{% hint style="info" %}
By default, all class members are sealed and cannot be overridden. To override we must expose it by using `abstract` or `virtual` keyword.
{% endhint %}

{% embed url="https://learn.microsoft.com/en-in/dotnet/csharp/language-reference/" fullWidth="false" %}

{% embed url="https://www.turing.com/interview-questions/c-sharp" %}

{% embed url="https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions" %}

{% embed url="https://google.github.io/styleguide/csharp-style.html" %}
