“字符串"不包含"IsNullOrWhiteSpace"的定义如何解决此错误? [英] 'string' does not contain a definition for 'IsNullOrWhiteSpace' how to solve this error?
本文介绍了“字符串"不包含"IsNullOrWhiteSpace"的定义如何解决此错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能知道.
它显示错误,如字符串"不包含"IsNullOrWhiteSpace"的定义如何解决此错误?
Can anyone know.
it show error like ,''string'' does not contain a definition for ''IsNullOrWhiteSpace'' how to solve this error?
public object SQLExecuteNonQuery(string procedureName, Hashtable cmdParms)
{
try
{
_SqlConnection = GetSQLConnection();
//Open SQL Connection
_SqlConnection.Open();
_SqlCommand = new SqlCommand(procedureName, _SqlConnection);
_SqlCommand.CommandType = CommandType.StoredProcedure;
//null or empty checking procdure name and hashtable
if (cmdParms.Count > 0 && !string.IsNullOrWhiteSpace(procedureName))
{
foreach (DictionaryEntry de in cmdParms)
{
//adding sql parameter
_SqlCommand.Parameters.Add(new SqlParameter(de.Key.ToString(), de.Value));
}
}
//Executing SQl Command
return _SqlCommand.ExecuteScalar();
}
推荐答案
string.IsNullOrWhiteSpace已添加到.net Framework 4.0及更高版本中.因此,您必须使用旧版本的.net框架.在项目设置中设置适当的.net框架.请参见此处 [
string.IsNullOrWhiteSpace was added to .net framework 4.0 and up. So you must be using older version of .net framework. Set the appropriate .net framework in your project settings. See here[^].
看起来像你尝试在旧版本的.Net中构建代码.
.NET 4.0之前的任何版本都不支持此方法.
Looks like you are trying to build code in an older version of .Net.
Anything before .Net 4.0 does not support this method.
String.NET 4中引入了IsNullOrWhiteSpace.如果您不针对.NET 4,则可以轻松编写自己的代码:
String.IsNullOrWhiteSpace has been introduced in .NET 4. If you are not targeting .NET 4 you could easily write your own:
public static class StringExtensions
{
public static bool IsNullOrWhiteSpace(string value)
{
if (value != null)
{
for (int i = 0; i < value.Length; i++)
{
if (!char.IsWhiteSpace(value[i]))
{
return false;
}
}
}
return true;
}
}
可以这样使用:
bool isNullOrWhiteSpace = StringExtensions.IsNullOrWhiteSpace("foo bar");
which could be used like this:
bool isNullOrWhiteSpace = StringExtensions.IsNullOrWhiteSpace("foo bar");
这篇关于“字符串"不包含"IsNullOrWhiteSpace"的定义如何解决此错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文