我是C#的新手,来自C++背景.在C++中,您可以这样做:
class MyClass{
....
};
int main()
{
MyClass object; // this will create object in memory
MyClass* object = new MyClass(); // this does same thing
}
Run Code Online (Sandbox Code Playgroud)
而在C#中:
class Program
{
static void Main(string[] args)
{
Car x;
x.i = 2;
x.j = 3;
Console.WriteLine(x.i);
Console.ReadLine();
}
}
class Car
{
public int i;
public int j;
}
Run Code Online (Sandbox Code Playgroud)
你不能这样做.我想知道为什么Car x不做它的工作.