所以,我有一个班学生,并且我创建了一个指向类student的对象的引用变量。我想要在我的代码中获取引用变量的名称。我想要o/p作为哈利(这是我的参考变量)。这件事可能吗?获取参考变量的名称
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
student harry = new student();
//OUTPUT:harry
}
}
public class student { }
}
将'public'添加到字段定义 – Grundy
您是否想要在代码中声明学生的姓名或变量的名称。 –
作为一个节点,请花时间阅读关于C#的约定。例如,您的类名应该用PascalCase编写。如果你关注他们,它会让每个人都更容易,并且当你学习语言时更容易接受他们。 –