Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Switch | Control Structures
C# Basics
course content

Kursusindhold

C# Basics

C# Basics

1. Getting Started
2. Dealing with Data Types
3. Control Structures
4. Loops
5. Arrays
6. Methods

book
Challenge: Switch

Complete the switch statement to output what day of the week it is.

cs

main

copy
1234567891011121314151617181920212223242526272829303132
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int day = 5; Console.Write("It is "); switch (day) { case 1: Console.WriteLine("Monday"); break; case 2: Console.WriteLine("Tuesday"); break; case 3: Console.WriteLine("Wednesday"); break; case 4: Console.WriteLine("Thursday"); break; default: Console.WriteLine("Invalid Day"); break; } } } }

Add the three missing cases for the days 5, 6 and 7.

cs

main

copy
1234567891011121314151617181920212223242526272829303132
using System; int day = 5; Console.Write("It is "); switch(day) { case 1: Console.WriteLine("Monday"); break; case 2: Console.WriteLine("Tuesday"); break; case 3: Console.WriteLine("Wednesday"); break; case 4: Console.WriteLine("Thursday"); break; case 5: Console.WriteLine("Friday"); break; case 6: Console.WriteLine("Saturday"); break; case 7: Console.WriteLine("Sunday"); break; default: Console.WriteLine("Invalid Day"); break; }

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 12

Spørg AI

expand
ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

course content

Kursusindhold

C# Basics

C# Basics

1. Getting Started
2. Dealing with Data Types
3. Control Structures
4. Loops
5. Arrays
6. Methods

book
Challenge: Switch

Complete the switch statement to output what day of the week it is.

cs

main

copy
1234567891011121314151617181920212223242526272829303132
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int day = 5; Console.Write("It is "); switch (day) { case 1: Console.WriteLine("Monday"); break; case 2: Console.WriteLine("Tuesday"); break; case 3: Console.WriteLine("Wednesday"); break; case 4: Console.WriteLine("Thursday"); break; default: Console.WriteLine("Invalid Day"); break; } } } }

Add the three missing cases for the days 5, 6 and 7.

cs

main

copy
1234567891011121314151617181920212223242526272829303132
using System; int day = 5; Console.Write("It is "); switch(day) { case 1: Console.WriteLine("Monday"); break; case 2: Console.WriteLine("Tuesday"); break; case 3: Console.WriteLine("Wednesday"); break; case 4: Console.WriteLine("Thursday"); break; case 5: Console.WriteLine("Friday"); break; case 6: Console.WriteLine("Saturday"); break; case 7: Console.WriteLine("Sunday"); break; default: Console.WriteLine("Invalid Day"); break; }

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 12
Vi beklager, at noget gik galt. Hvad skete der?
some-alt