So I've been trying to get this to work for 3 days and I'm close to it working, I think! I have tried making it in the console and in GUI of Visual Studio, when I make it in the GUI I am getting a error in visual studio "The class name '?' is not a valid identifier for this language." - I think the compiler is erroring for some reason
When I make it as a console application I get my string array erroring " (Variable name) Does not exist in current context" - I know what this means but I have made the array available globally and also made it it's own class, like so: "public static class Global"
In the console version I also get: "Use of unassigned local variable 'desc1'" I have tried putting my local variables in various places to no adieu.
Here is my console code, I'm trying to get it to work there then convert it to a GUI so I need some help with the GUI error I'm getting. The ""The class name '?' is not a valid identifier for this language." error. I looked it up on the MSDN and they recommended closing and opening it (solution) again which didn't work.
(Console code):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AnotherFlexibleOrder
{
public static class Global
{
public static int[] itemNumber = { 112, 123, 134, 213, 224, 235 };
public static string[] description = { plate, cup, bowl, vase, planter, statue };
public static double[] price = { 16.95, 10.95, 14.25, 21.95, 45.99, 89.99 };
public static bool isValidOption = false;
}
class Program
{
static void Main(string[] args)
{
int number;
Console.WriteLine("Please enter an item number or description.");
string item = Console.ReadLine();
if (int.TryParse(item, out number))
{
GetDetails(number);
}
else
{
GetDetails(item);
}
}
private static void GetDetails(int num)
{
string desc1;
double price1;
for (int x = 0; x < Global.itemNumber.Length; ++x)
{
if (num == Global.itemNumber[x])
{
Global.isValidOption = true;
desc1 = Global.description[x];
price1 = Global.price[x];
}
if (Global.isValidOption)
{
Console.WriteLine("You selected item # {0} which is {1} and costs {2}.", num, desc1, price1);
}
else
{
Console.WriteLine("Invalid item #.");
}
}
}
private static void GetDetails(string word)
{
string desc1;
int item1;
double price1;
for (int x = 0; x < Global.description.Length; ++x)
{
if (word == Global.description[x])
{
Global.isValidOption = true;
desc1 = Global.description[x];
price1 = Global.price[x];
item1 = Global.itemNumber[x];
}
if (Global.isValidOption)
{
Console.WriteLine("You selected {0} which is item # {1} and costs {2}.", desc1, item1, price1);
}
else
{
Console.WriteLine("Invalid item1 #!");
}
}
}
}
}
It's that string in the global class that is giving me the "does not exist in current context" errors: "The name 'plate' does not exist in the current context"
Then my local variables in the GetDetails() methods are giving me this error: "Use of unassigned local variable 'price1'"
This is for my homework, we have to overload the GetDetails method. I was able to get the code working more or less but I just can't figure these errors out I swear I did everything right.
What am I missing? I have tried putting the variables in several places and I debugged to the best of my abilities. There might be other logical errors but I can't get it to compile to debug any further.
What I have tried:
I have tried putting the variables and arrays in different places to get them to be global or local.
Tried restarting solution in visual studio when I get "The class name '?' is not a valid identifier for this language."