110,561
社区成员
发帖
与我相关
我的任务
分享
public class SVC()
{
public static int count=0;
}
private void test118(object obj,string name)
{
while (true)
{
Thread.Sleep(1);
Console.WriteLine(obj.GetType().GetFields().FirstOrDefault(f => f.Name == name).GetValue(obj));
}
}
private void buttonLogin_Click(object sender, EventArgs e)
{
//现有SVC类,里面存的是一些静态变量,我通过test118方法,传过去该类的实例和该类的一个变量名称,
//然后不断循环输出SVC.count的值,在循环里要想获取值每次都要用反射,
//有没有可能在循环外声明一个int b随着SVC.count的值改变而改变; 因为这样我就可以直接Console.WriteLine(b)了;
test118(new SVC(),"count");
}
class MyIntClass
{
int _v;
public static implict operator int(MyIntClass myInt)
{
return myInt._v;
}
public static implict operator MyIntClass (int i)
{
return new MyIntClass { _v = i };
}
//还有equals,tostring,==,!=
}