我正在尝试将c#代码转换为vb.net,但我很难转换符号“?”在c#到vb.net。这里我的代码转换
public audit_trail Mapper(IDataReader rdr)
{
audit_trail audit_trail = new audit_trail();
audit_trail.Log_id = rdr["Log_id"] is DBNull ? 0 : (int)rdr["Log_id"];
audit_trail.Host = rdr["Host"] is DBNull ? string.Empty : (string)rdr["Host"];
return audit_trail;
}
如何转换标志“?”到vb.net ??
我想转换
audit_trail.Host = rdr["Host"] is DBNull ? string.Empty : (string)rdr["Host"];
类似
if rdr["Host"] is DBNull.Value then
audit_trail.Host = string.Empty
else
audit_trail.Host = rdr["Host"]
end if
但代码太长,代码行太多..你们有没有想过转换成短代码?
答案 0 :(得分:6)
三元运算符的可视基本语法是If([condition,] op1, op2)
。
答案 1 :(得分:4)
audit_trail.Host = If(IsDBNull(rdr("Host")), String.Empty, CType(rdr("Host"), String))