Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无论c中的条件如何,字符串的值都设置为null#_C# - Fatal编程技术网

C# 无论c中的条件如何,字符串的值都设置为null#

C# 无论c中的条件如何,字符串的值都设置为null#,c#,C#,我正在给c中的var赋值# 现在我面临的问题是,不管properties.AfterProperties[“Name”] 我检查了带有文件名的properties.AfterProperties[“Name”]的值,还检查了即时窗口中的整个赋值语句,并将properties.AfterProperties[“Name”]的值赋值给文件名 但当我在该赋值行后按f11时,fileName的值为空 这取决于后置属性的类型 在第一个条件中,您使用了properties.AfterProperties[“

我正在给c中的var赋值#

现在我面临的问题是,不管
properties.AfterProperties[“Name”]

我检查了带有文件名的
properties.AfterProperties[“Name”]
的值,还检查了即时窗口中的整个赋值语句,并将
properties.AfterProperties[“Name”]
的值赋值给
文件名


但当我在该赋值行后按f11时,
fileName
的值为空

这取决于
后置属性的类型

在第一个条件中,您使用了
properties.AfterProperties[“Name”]
,但在分配中,您使用了
properties.AfterProperties[“Name”].ToString()


可能
properties.AfterProperties[“Name”]
不为null,但
properties.AfterProperties[“Name”].ToString()返回null。

可能会这样尝试:


字符串文件名=!properties.AfterProperties[“Name”]。是否等于(null)?properties.AfterProperties[“Name”].toString():“”

您也可以试试这个

string fileName  = properties.AfterProperties["Name"] != null && !String.IsNullOrEmpty(properties.AfterProperties["Name"].toString()) ? properties.AfterProperties["Name"].toString(): "";
顺便提醒一下:

properties.AfterProperties["Name"] != null // This check avoids object reference errors.

!String.IsNullOrEmpty(properties.AfterProperties["Name"].toString()) // This check will avoid your problem - returning empty instead of null.

希望这能有所帮助。

我还尝试删除了.toString():(但没有成功)后属性的类型是什么?
properties.AfterProperties["Name"] != null // This check avoids object reference errors.

!String.IsNullOrEmpty(properties.AfterProperties["Name"].toString()) // This check will avoid your problem - returning empty instead of null.