这是.Net C#String的后续问题.如果元素值为null,如何输出"null"而不是空字符串?答案建议使用??运算符来定义自定义空值,但替换永远不会被触发.
DataSet myDataSet = new DataSet();
mySqlDataAdapter.Fill(myDataSet);
DataTable rotationData = myDataSet.Tables["Table"];
rotationValues = string.Join(", ",
from r in rotationData.Rows.OfType<DataRow>()
select r[5] ?? "null");
Run Code Online (Sandbox Code Playgroud)
当我将代码更改为:
rotationValues = string.Join(", ",
from r in rotationData.Rows.OfType<DataRow>()
select r[5].GetType());
Run Code Online (Sandbox Code Playgroud)
我可以观察到其中包含有效数据System.Double的元素的数据类型是NULL,而元素的数据类型是NULL System.DBNull.难道??不是操作上System.DBNull?