Skip to main content

C-Sharp

Gängige Syntax

If-else

public static bool LoginCheck(string username, string password)
{
if (DBCheck(username, password) == 0)
{
return true;
} else
{
Console.WriteLine("Daten falsch!");
return false;
}

}

Switch

public static bool LoginCheck(string username, string password)
{
switch (DBCheck(username, password))
{
case 0:
return true;
break;
case 1:
case 2:
Console.WriteLine("Daten falsch!");
return false;
break;
}

}

Schleifen

public static void Test(string username, string password)
{
string[] test = {"Volvo", "BMW", "Ford", "Mazda"};

for (int i=0; i < test.Length; i++)
{
Console.WriteLine(test[i]);
}

foreach (string car in test)
{
Console.WriteLine(car);
}

while(true)
{
Console.WriteLine("True");
}

do
{
Console.WriteLine("Do");
}
while (true);

}

Objekt Instanzieren

public class User
{
public int UserID { get; set; }
public string Name { get; set; }

public User(int userID, string name)
{
UserID=userID;
Name=name;
}
}


public static void Test()
{
User user = new User(1, "Felix");
}

Typische Aufgaben

  • Code korrigieren
  • Einfache Schleifen über ein Array
  • if-Abfragen mitthilfe vorhandener Methoden