Coding made easy Code with me C#

Basics

What is C#

You can use C# to create windows applications, web servers, mobile applications and many works like angular and Node.js.

The .NET Frameworks

The .NET Frameworks consists of the common languages Runtime (CRL) and the .NET Frameworks class library.

The is the foundation of the .NET Frameworks. It manages code at the execution time providing core services such as memory management, code accuracy, and many if the other aspects of your code.

The class library is a collection of classes, interference and values allows you to accomplish a common range of programming tasks, such as data collection, file access, and working with text

C# programs use the .NET Framework class library extensively to do common tasks and provide various functionalities.

Basics

Variable

Creating a variable reserves a memory location, or a space in memory, for storing values. It is called variable because the

To use a variable, it must first be declared by specifying the name and data type.

A variable name, also called an identifier, can contain letters, numbers and the underscore character (_) and must start with a letter or underscore.

Although the name of a variable can be any set of letters and numbers, the best identifier is descriptive of the data it will contain. This is very important in order to create clear, understandable and readable code!

A data type defines the information that can be stored in a variable, the size of needed memory and the operations that can be performed with the variable.
For example, to store an integer value (a whole number) in a variable, use the int keyword:

The code above declares a variable named myAge of type integer.

You can assign the value of a variable when you declare it:

There are a number of built-in data types in C#. The most common are:
int — integer.
float — floating point number.
double — double-precision version of float.
char — a single character.
bool — Boolean that can have only one of two values: True or False.
string — a sequence of characters.
The statements below use C# data types:

To create a C# program, you need to install an integrated development environment (IDE) with coding and debugging tools.
We will be using Visual Studio Community Edition, which is available to download for free.
After installing it, choose the default configuration.
Next, click File->New->Project and then choose Console Application as shown below:

Visual Studio will automatically generate some code for your project:

You will learn what each of the statements does in the upcoming lessons.
For now, remember that every C# console application must contain a method (a function) named Main. Main is the starting point of every application, i.e. the point where our program starts execution from.

Displaying Output

Many of the applications are require some input from the user and give output as a result.

To display text to the console.write or console.write methods

moves the cursor to the next line after the text output.
The program below will display Hello World! to the console window:

we can display values to the console window.

Getting User Input

You can also prompt the user to enter data and the use the Console.ReadLine Method to assign the input to a string variable.

The console.ReadLine() method returns a string value.

If you are excepting antother type of value (such as int or double), the entered data must be converted to that type.

This can be done by using the Convert ToXXX methods is the .NET name of the type of that we want to convert to. For example the methods include Convert.ToDouble and Convert. ToBoolean. For integer conversion there are three alternatives available based on the bit size of the integer.

Comments

Comments are the explanatory statement that you can include in a program to benefit the reader of your code.

Like for example

// Peints Hello

Console.WriteLine(“Hello”);

The compiler ignores everything that appears in the comment, so none of that information affects the results.

A comment begins with two slashes (//) is called single line comment. The slashes tells the compiler to ignore everything that follows, until the end of the line.

Multi Line Comments

Comments that requires multiple lines begin with /* and end with */ at the end of the comments block.

You can place them on the same line or insert one or more lines between them

For Example

/*Some long

Comment text

*/

THE VAR KEYWORD
A variable can be explicitly declared with its type before it is used.

Alternative, C# provides a handy function to enable the compiler to determine the type of the variable.

THE VARIABLE KEYBOARD

Variables declared using the var keyword are called implicitly typed variables.
Implicitly typed variables must be initialized with a value.
For example, the following program will cause an error:

CONSTANTS

Constants store a value that cannot be changed from their initial assignment.
To declare a constant, use the const modifier.

The value of const PI cannot be changed during program execution.

Arithmetic Operators

C# supports the following arithmetic operators:

FOR EXAMPLE
int x = 14;

Int y = 20;

Console.writeLine(x+y)

DIVISION

The division operator (/) devides the first operand by the second. If the operand are both integers, any other reminder is dropped in order to return an integer value.

MODULUS
the modulus operator (%) is informally known as remainder operator because it returns the remainder of an integer division.

OPERATOR Precedence

The operator precedence determines the grouping terms in an expressions is evaluated. Certain operators take higher precedence over others.

The program evaluates 3*2 first and the result to 4. As in maths, using parenthesis alters operator precedence.

Assignment Operators

The assignment operator assigns the value on the right side of the operator to the variable on the left side.

C# also combined assignment operators that performs and an assignment in one statement.

The same shorthand syntax applies to the multiplication, devision, and modulus operators

INCREMENT Operators

The increment operators is used to increase an integer’s value by one and is a commonly used C# operator.

Prefix and Postfix Forms

The increment operators has two forms, prefix and postfix.

Prefix- increments the value and then procedes with the expression.

Postfix-eveluates the expressions and then performs the incrementing.

DECREMENT OPERATOR

The decrement operator ( — ) works in much the same way as the increment operator but instead of increasing value it decreases by one.

Sometimes I write, sometimes I write well…:)