为什么这段代码(在我的表单的 _Load()
事件中):
FileVersionInfo vi = FileVersionInfo.GetVersionInfo(_fullPath);
String VersionInfo = vi.FileVersion;
if (VersionInfo.Trim().Equals(String.Empty)) {
VersionInfo = NO_VERSION_INFO_AVAILABLE;
}
textBoxVersionInfo.Text = VersionInfo;
...当 VersionInfo == ""
为真时给我以下错误消息?
System.NullReferenceException was unhandled Message=Object reference not set to an instance of an object.*
最佳答案
你应该在这里使用 String.IsNullOrEmpty
方法。 See MSDN
if (String.IsNullOrEmpty(VersionInfo)) {
VersionInfo = NO_VERSION_INFO_AVAILABLE;}
关于c# - 空字符串是空引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10147387/