C# course 1

2. How to check .N Core version

in cmd line:

dotnet --version

2. first program

using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
//komentarz…
Console.WriteLine("Hello World!");
Console.ReadLine();
}
}
}

3. logical operands

//&& - and
// || - or

4. comments

//komentarz…
//Console.WriteLine("Hello World!");

5. integers
        int x;
        x = 1;

6. boolean

//bool 
bool isCorrect = true;

isCorrect = false;

//negacja
bool foo = !isCorrect;

int boo = 5;
int goo = 6;

//you can use this assertion
bool isEqual = boo == goo;

7. double/decimal (used for Money precision)

double doubleNumber = 21.37;

Console.WriteLine(doubleNumber);

decimal decimalNumber = 21.37M;

Console.WriteLine(decimalNumber);

int sum = goo % boo; //modulo

8. strings and operations in strings

  
    //string
    string txt = "aaa";
    Console.WriteLine(txt);

    //laczenie stringow
    Console.WriteLine("Txt:" + txt);

    //interpolacja ciagu (??)
    Console.WriteLine($"Hello World {txt},{txt}");

    txt.ToUpper(); //zamienia na duze litery

    //char
    char c = 'a';

    var variable = 1; //szybko podmienia na wlasciwy typ

    //konwersja na string
    var intToString = variable.ToString();

//konwersja na int (uwaga trzeba lapac wyjatki, gdy niemozliwa)
    var stringToInt = Convert.ToInt32(a);

9. loops:

a. while

while (isCorrect==false)
{
if (n == randomNo)
{
Console.WriteLine("Super ! zgadles");
isCorrect = true;
}
else if (n > randomNo)
{
Console.WriteLine("za duza");
n = Convert.ToInt16(Console.ReadLine());
}
else if (n < randomNo)
{
Console.WriteLine("za mala");
n = Convert.ToInt16(Console.ReadLine());
}
}

b. for

for (int i=0;i<5;i++)
{
//
}

c. tables (collections)

//vector (one dimensional table)
int[] table = new[] { 1, 2, 3, 4, 5 };
Opublikowany w C#Tagged

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany.