0
struct MyStruct : int
{
   .../...
}

MSDN声明之后是已实现接口的:列表,但int对我来说这是一个非常奇怪的接口......

这可能是一种定义结构大小的方法吗?有点像位域?

4

3 回答 3

10

It is illegal and means nothing whatsoever.

Error 5 Type 'int' in interface list is not an interface redacted\Program.cs 13 23 ConsoleApplication9

However! If by int you mean "an interface", then it means: "this is a value-type that implements an interface"

You can't, however, have an interface called int, since int is a reserved keyword. You would have to refer to that as @int in the C#.

于 2012-07-24T09:45:37.847 回答
0

看起来 Struct 实际上应该说 Enum,那么它就会有意义。

于 2012-07-24T10:02:22.150 回答
0

这里struct MyStruct : int不是一个接口,所以编译器会失败

如果你有 Resharper,它会在运行构建之前通过红色下划线来警告你

因为知识 int 是System.Int32的别名,它是一个结构

于 2012-07-24T09:47:33.977 回答