小编Pie*_*tro的帖子

C# - 2个结构问题

我知道结构是值类型,但后来我不明白为什么这样有效:
编辑:我的意思是,为什么this.Size.Height不起作用呢?

struct A
{
    int height;

    public int Height
    { 
        get
        {
            return height;
        }

        set
        {
            height = value;
        }
    }
}

//... class Main
{
    A a = A();
    a.Height = 5;  //works. Why? I thought it should say "cannot modify as it is not variable". I think the properties should return copy of this struct...?
}
Run Code Online (Sandbox Code Playgroud)

第二个问题 - 我已经阅读过我不需要使用带有结构的"新"但如果没有它我就无法使用它.

c# struct properties

1
推荐指数
1
解决办法
233
查看次数

标签 统计

c# ×1

properties ×1

struct ×1