考虑以下具有2个可选变量的函数
public List<T> SelectSqlItems<T>(
string settingsgroup = null,
int? state = null)
{
SqlCommand selectCommand = null;
if (settingsgroup == null)
{
selectCommand = new SqlCommand(
"select * from ApplicationSettings ", con);
}
else
{
selectCommand = new SqlCommand(
string.Format(
"select * from ApplicationSettings where settingsgroup='{0}' ",
settingsgroup),
con);
}
if (state != null)
{
selectCommand.CommandText +=
!selectCommand
.CommandText
.ToLower()
.Contains("where")
? string.Format("where state={0}", state)
: string.Format("and state={0}", state);
}
//etc..
}
Run Code Online (Sandbox Code Playgroud)
我有4种可能性:
settingsgroup==null && state==null
settingsgroup==null && state!=null
settingsgroup!=null …Run Code Online (Sandbox Code Playgroud) 首先,看看下面的简单代码.
int main(){
char *name;
cout << "Enter your name: ";
cin >> name;
cout << "Your name is: " << name;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
前面的代码给了我一个错误warning: deprecated conversion from string constant to 'char*'.
但我通过以下方式解决了这个问题:
const char *name;
Run Code Online (Sandbox Code Playgroud)
编译代码后,我有另一个错误no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' and 'const char*').
上一次错误的原因是什么,以及如何解决?
我试图将字符串从文本框传递到同一个类中的方法,但是当我尝试这样做时,我收到一条错误消息:
no overload method, TotalWeighting takes one argument.
尽管在我试图发送的方法的参数中包含了每个对象.调用方法的位置出现错误消息.
这是程序的底部:
public void textBox7_TextChanged(object sender, EventArgs e)
{//Assignment 6, box 1
string STRtb11 = textBox7.Text;//Get value from textBox7 and set to new varaible STRtb10
TotalWeighting(STRtb11);
}
public void textBox12_TextChanged(object sender, EventArgs e)
{//Assignment 6, box 2
string STRtb12 = textBox12.Text;//Get value from textBox12 and set to new varaible STRtb11
TotalWeighting(STRtb12);
}
public static double TotalWeighting(string STRtb1, string STRtb2, string STRtb3, string STRtb4, string STRtb5, string STRtb6, string STRtb7, string STRtb8, string …Run Code Online (Sandbox Code Playgroud)