C#C
C#5mo ago
ZHYAKO

✅ This label has not been referenced error by "defualt:"

this code sample about switch case

using System;

class TestProject8

{
        public static void Main(string[] args)

        {

                int employeeLevel = 200;

                string employeeName = "John Smith";

  

                string title = "";

  

                switch (employeeLevel)

                {

                        case 100:

                                title = "Junior Associate";

                                break;

  

                        case 200:

                                title = "Senior Associate";

                                break;

  

                        case 300:

                                title = "Manager";

                                break;

  

                        case 400:

                                title = "Senior Manager";

                                break;

  

                        defualt:

                                title = "Associate";

                }

  

                Console.WriteLine($"{employeeName}, {title}");

        }

}


generated these warnings

warning CS0162 and CS0164 on "defualt:" line
warning CS0162: unreachable code detected
warning CS0164: This label has not been referenced




MSDN

// CS0164.cs 
// compile with: /W:2 
public class Program { 
public static void Main() { 
int i = 0; 
l1: // CS0164
i++;
// Uncomment the following lines to resolve this warning.
// if (i < 10)
// goto l1; }


no explanation about l1: could be find on google or any documentations. 🙂


Please if someone could explain why defualt: generated those two errors (warnings) I would be grateful.

Thanks in advance XO
Was this page helpful?