自动财产默认值

编程入门 行业动态 更新时间:2024-10-13 12:21:14
本文介绍了自动财产默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复:结果的你如何给一个C#自动属性的默认值?

有没有提供一个自动的财产?

Is there any nice way to provide a default value for an automatic property?

公众诠释HowHigh {搞定;组; } //默认为0

如果没有明确设定的任何地方,我想这是5.你知道它一个简单的方法?例如。我可以设置它的构造函数或什么的,但是这不是优雅

If not explicitly set anywhere, I want it to be 5. Do you know a simple way for it? E.g. I could set it in constructor or something, but that's not elegant.

更新:C#6已经得到了它:的 geekswithblogs/WinAZ/archive/2015/06/ 30 / whatrsquos-新的-C-6.0自动财产initializers.aspx

UPDATE: C# 6 has got it: geekswithblogs/WinAZ/archive/2015/06/30/whatrsquos-new-in-c-6.0-auto-property-initializers.aspx

推荐答案

如果该该类型的默认值是不够的,那么这样做是通过一个构造的唯一途径。

If the default value for the type is not sufficient, then the only way to do it is via a constructor.

更多推荐

自动财产默认值

本文发布于:2023-07-15 13:06:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1111393.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:默认值   财产

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!