using System;
using myDll;
using System.Diagnostics;
using hellowworld.calc;
namespace Hellowworld
{
struct compareWithInt
{
public string name;
public int age;
public int height;
}
class Hellow
{
static void Main()
{
compareWithInt compareWithInt = new compareWithInt();
compareWithInt.name = "yxj";
compareWithInt.age = 22;
compareWithInt.height = 183;
//compareWithInt = 19; //无法将int类型显示转换为Hellowworld.compareWithInt
int compareWithStruct = new int();
compareWithStruct = 22;
Console.WriteLine(compareWithStruct); //弹出来的是22
Console.ReadKey();
}
}
}
我先学的基础类型,后来学的结构体,然后了解到几乎所有的值类型都是结构体,但是我试了一下,发现了一个问题,问什么我自己定义的结构compareWithInt(其中有三个实例字段)只能给实例的字段成员赋值(这符合我的逻辑) 然而 int类型创建的对象可以直接给这个对象本身复制。