Program4Food
Active member
- Joined
- Nov 22, 2021
- Messages
- 40
- Programming Experience
- 10+
I was learning the switch case function and was adding line 25, and I have no clue what happened (maybe I hit another key somewhere??) and then
I got several errors and I don't even understand them in order for me to resolve it.
Some of the errors I am looking at make no sense when you review the line of code it references, and I never even changed that line! (line 21)
I need to know what the error is trying to cryptically tell me so I can prevent/fix in the future.
Error 9 Type or namespace definition, or end-of-file expected F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 57 9 Console-switch_case
Error 12 The type or namespace name 'iAttribute' could not be found (are you missing a using directive or an assembly reference?) F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 32 90 Console-switch_case
Error 14 The type or namespace name 'iAttribute' could not be found (are you missing a using directive or an assembly reference?) F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 34 34 Console-switch_case
Error 11 The type or namespace name 'i' could not be found (are you missing a using directive or an assembly reference?) F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 32 90 Console-switch_case
Error 13 The type or namespace name 'i' could not be found (are you missing a using directive or an assembly reference?) F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 34 34 Console-switch_case
Error 1 Newline in constant F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 24 31 Console-switch_case
Error 3 Invalid token '=' in class, struct, or interface member declaration F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 21 22 Console-switch_case
Error 2 Invalid token '{' in class, struct, or interface member declaration F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 13 9 Console-switch_case
Error 4 Invalid token '{' in class, struct, or interface member declaration F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 21 36 Console-switch_case
Error 6 Expected class, delegate, enum, interface, or struct F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 32 92 Console-switch_case
Error 7 Expected class, delegate, enum, interface, or struct F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 34 36 Console-switch_case
Error 5 A namespace cannot directly contain members such as fields or methods F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 22 13 Console-switch_case
Error 8 A namespace cannot directly contain members such as fields or methods F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 54 13 Console-switch_case
Error 10 'Console_switch_case.Program.MyValues' is a 'field' but is used like a 'type' F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 21 13 Console-switch_case
I got several errors and I don't even understand them in order for me to resolve it.
Some of the errors I am looking at make no sense when you review the line of code it references, and I never even changed that line! (line 21)
I need to know what the error is trying to cryptically tell me so I can prevent/fix in the future.
C#:
using System;
using System.Collections.Generic;
using System.Text;
namespace Console_switch_case
{
class Program
{
static void Main(string[] args)
{
}
{
// define variables
string[] MyValues;
int ValuesLength;
string MyValuesCombined;
MyValues = new String[]{"one", "two", "three", "four", "five"};
MyValuesCombined = string.Join(",", MyValues);
ValuesLength = MyValues.Length;
Console.WriteLine("The number of elements in MyValues is {0}\r\n\", ValuesLength);
Console.WriteLine("The elements of the string array is {0}\r\n\r\n", MyValuesCombined);
for (int i = 0; i < ValuesLength; i++)
{
// Console.WriteLine("Value of i: {0}", i);
Console.WriteLine("Element number {0} has the value of {1}", i, MyValues[i]);
switch (MyValues[i])
{
case "one":
Console.WriteLine("one spelled out is the number 1");
break;
case "four":
Console.WriteLine("four spelled out is the number 4");
break;
}
Console.WriteLine("\r\n\r\n");
}
// pause for key press
Console.WriteLine("\r\n\r\nPress a key to exit...");
Console.ReadKey();
}
}
}
Error 9 Type or namespace definition, or end-of-file expected F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 57 9 Console-switch_case
Error 12 The type or namespace name 'iAttribute' could not be found (are you missing a using directive or an assembly reference?) F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 32 90 Console-switch_case
Error 14 The type or namespace name 'iAttribute' could not be found (are you missing a using directive or an assembly reference?) F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 34 34 Console-switch_case
Error 11 The type or namespace name 'i' could not be found (are you missing a using directive or an assembly reference?) F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 32 90 Console-switch_case
Error 13 The type or namespace name 'i' could not be found (are you missing a using directive or an assembly reference?) F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 34 34 Console-switch_case
Error 1 Newline in constant F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 24 31 Console-switch_case
Error 3 Invalid token '=' in class, struct, or interface member declaration F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 21 22 Console-switch_case
Error 2 Invalid token '{' in class, struct, or interface member declaration F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 13 9 Console-switch_case
Error 4 Invalid token '{' in class, struct, or interface member declaration F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 21 36 Console-switch_case
Error 6 Expected class, delegate, enum, interface, or struct F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 32 92 Console-switch_case
Error 7 Expected class, delegate, enum, interface, or struct F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 34 36 Console-switch_case
Error 5 A namespace cannot directly contain members such as fields or methods F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 22 13 Console-switch_case
Error 8 A namespace cannot directly contain members such as fields or methods F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 54 13 Console-switch_case
Error 10 'Console_switch_case.Program.MyValues' is a 'field' but is used like a 'type' F:\VisualStudio\2012\Console-switch_case\Console-switch_case\Program.cs 21 13 Console-switch_case