[英]In XNA, how do I modify something in the main game class from another class?
[英]How do I access something from a virtual class so I can use them for If/Else statements in the MAIN class?
class Registration
{
public virtual void Register()
{
int Registration_System;
Console.Write("Registration System");
Console.Write("\n 1. Add Student" +
"\n 2. View Student" +
"\n 3. Search" +
"\n 4. Edit" +
"\n 5. Delete" +
"\n 6. Exit");
Console.Write("\nChoose: "); Registration_System = int.Parse(Console.ReadLine());
}
}
class Program //Main class
{
static void Main(string[] args)
{
Registration r = new Registration();
r.Register();
MSIT it = new MSIT();
MSCS cs = new MSCS();
}
}
所以基本上我需要访问Registration_System的值,以便在Main类的if / else系统中使用它们:
if (Registration_System == 1)
{
}
..
因为我错过了几节课,所以我将与至少6个其他班级一起做。 到目前为止,我只需要为If / Else设置一个框架,这样我就可以访问所有其他类,但是如果不使用Registration_System的值就无法做到这一点。 我可以正确执行吗? 还有另一种方法吗?
使用它作为Register函数的返回值怎么样?
public virtual int Register()
{
....
return Registration_System;
}
首先,在C#中没有所谓的虚拟类。 我想,您的意思是虚拟方法(?)。 无论如何,如果要访问Main类中的Registration_System
的值,则必须将其设置为Registration
类中的公共全局变量,或者将其封装在公共属性中(同样在同一Registration
类中)如cpl所述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.