What is the difference between String.Empty and “” (empty string)?

后端 未结 17 1844
礼貌的吻别
礼貌的吻别 2020-11-22 03:25

In .NET, what is the difference between String.Empty and \"\", and are they interchangable, or is there some underlying reference or Localization i

17条回答
  •  故里飘歌
    2020-11-22 04:23

    Coming at this from an Entity Framework point of view: EF versions 6.1.3 appears to treat String.Empty and "" differently when validating.

    string.Empty is treated as a null value for validation purposes and will throw a validation error if it's used on a Required (attributed) field; where as "" will pass validation and not throw the error.

    This problem may be resolved in EF 7+. Reference: - https://github.com/aspnet/EntityFramework/issues/2610 ).

    Edit: [Required(AllowEmptyStrings = true)] will resolve this issue, allowing string.Empty to validate.

提交回复
热议问题