I’ve trying to learn c# but keep coming across a problem. Essentially, I’m trying to learn how to create a class that does some function and is called to perform that function by the application.
the error I have ended up with (there have been loads of others but I’ve tried to play around to ‘fix’ them) is
is a 'type' but is used like a variable
the code I’ve put together so far is;
namespace FirstConsoleApplication
{
class Program
{
public class checkConvertValue
{
public string formula1(string x)
{
Int32 isnumber = 0;
bool canConvert = Int32.TryParse(x, out isnumber);
string returnValue;
if (canConvert == true)
{
int val3 = Int32.Parse(x);
switch (val3)
{
case 50:
returnValue = "yep its 50";
break;
case 51:
returnValue = "hmmm.... its 51... what are you gonna do about that??";
break;
case 52:
returnValue = "lets not get sloppy now...";
break;
default:
returnValue = "nope, its definately something else";
break;
};
}
else
{
returnValue = "Thats not a number";
};
return returnValue;
}
}
static void Main(string[] args)
{
string num;
string result1;
do
{
Console.WriteLine("Guess what the value is, hint... its integer and between 1 and 100");
num = Console.ReadLine();
result1 = checkConvertValue(num);
Console.WriteLine(result1);
} while (result1 != "yep its 50");
Console.ReadLine();
}
}
}
can someone let me know where I’m going wrong?
You are trying to access the function by class name, which is wrong. You have to do like this