Difference between revisions of "C Sharp"
From Teknologisk videncenter
Line 16: | Line 16: | ||
{ | { | ||
string ope = Console.ReadLine(); | string ope = Console.ReadLine(); | ||
− | + | ||
if (ope == "+") | if (ope == "+") | ||
{ Plus(); } | { Plus(); } | ||
Line 61: | Line 61: | ||
Console.WriteLine("Skriv subnetets prefix: "); | Console.WriteLine("Skriv subnetets prefix: "); | ||
int prefix = Convert.ToInt32(Console.ReadLine()); | int prefix = Convert.ToInt32(Console.ReadLine()); | ||
− | + | ||
String Sub1 = ""; | String Sub1 = ""; | ||
String Sub2 = ""; | String Sub2 = ""; | ||
String Sub3 = ""; | String Sub3 = ""; | ||
String Sub4 = ""; | String Sub4 = ""; | ||
− | + | ||
if (prefix > 7) | if (prefix > 7) | ||
{ | { |
Revision as of 12:41, 6 December 2016
Kode eksempler - Gentelman klub
Console.WriteLine("Skriv din alder"); string alder = Console.ReadLine(); int age; age = Convert.ToInt32(alder); if (((age > 20) && (age < 80)) || age != 21) { Console.WriteLine("Velkommen!"); } else { Console.WriteLine("gå hjem og spil OverWatch"); } Console.ReadLine();
static void Main(string[] args) { string ope = Console.ReadLine(); if (ope == "+") { Plus(); } else if (ope == "-") { minus(); } else { Console.WriteLine("det var ikke en gyldig operator"); } Console.ReadLine(); } static void Plus() { int tal1 = Convert.ToInt32(Console.ReadLine()); int tal2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(tal1 + tal2); } static void minus() { int tal1 = Convert.ToInt32(Console.ReadLine()); int tal2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(tal1 - tal2); }
loop's
int counter = 0; while(counter < 100) { Console.WriteLine(counter); }
int counter = 200; string test = "hello world"; foreach (char i in test) { Console.WriteLine(i); }
Subnet Calculator
Console.WriteLine("Skriv subnetets prefix: "); int prefix = Convert.ToInt32(Console.ReadLine()); String Sub1 = ""; String Sub2 = ""; String Sub3 = ""; String Sub4 = ""; if (prefix > 7) { Sub1 = "11111111"; } else { for (int i = 0; i < prefix; i++) { Sub1 = Sub1 + "1"; }
//Sub1 = Convert.ToString(prefix,2); while (Sub1.Length < 8) { Sub1 = Sub1 + "0"; } } Console.WriteLine(Sub1);