Does C# have an equivalent to Scala's structural typing?

后端 未结 4 494
小鲜肉
小鲜肉 2020-12-20 11:30

In Scala, I can define structural types as follows:

type Pressable = { def press(): Unit }

This means that I can define a function or method whi

4条回答
  •  余生分开走
    2020-12-20 11:55

    No, and no plans that I know of. Only named (rather than structural) subtyping (e.g. interfaces).

    (Others may want to see also

    http://en.wikipedia.org/wiki/Nominative_type_system

    http://en.wikipedia.org/wiki/Structural_type_system

    )

    (A few people may point out some exotic corner cases, like the foreach statement using structural typing for GetEnumerator, but this is the exception rather than the rule.)

提交回复
热议问题