gpt4 book ai didi

c# - 结构、接口(interface)和装箱

转载 作者:IT王子 更新时间:2023-10-29 03:55:02 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Is it safe for structs to implement interfaces?

拿这段代码:

interface ISomeInterface
{
public int SomeProperty { get; }
}

struct SomeStruct : ISomeInterface
{
int someValue;

public int SomeProperty { get { return someValue; } }

public SomeStruct(int value)
{
someValue = value;
}
}

然后我在某个地方这样做:

ISomeInterface someVariable = new SomeStruct(2);

在这种情况下 SomeStruct 是装箱的吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com