© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•6mo ago•
5 replies
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}");

        }

}
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; }
// 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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Getting $StandardIn has not been redirected.$ Error...
C#CC# / help
3y ago
Connection property has not been initialized
C#CC# / help
2y ago
✅ confused by this error
C#CC# / help
2y ago