C# default value in constructor same as two constructors for serialization

血红的双手。 提交于 2019-12-01 03:59:19

No. It unfortunately is not a default constructor.

When you write:

public MyClass(string description = null) { .... }

You're actually making a constructor that accepts a string parameter, but has an attribute marking the default value for that attribute. This is different than having a default constructor on the class.

Yes, you will have problems in that case.

I've tried to call a constructor described by you via reflection, and it thrown TargetInvokationException: (Argument count mismatch).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!