我试图将表名作为参数传递给我的查询,SqlCommand但它似乎没有工作.这是我的代码;
SqlConnection con = new SqlConnection( "server=.;user=sa;password=12345;database=employee" );
con.Open( );
SqlCommand cmd = new SqlCommand( "drop table @tbName" , con );
cmd.Parameters.AddWithValue( "@tbName" , "SampleTable" );
cmd.ExecuteNonQuery( );
con.Close( );
Run Code Online (Sandbox Code Playgroud) 我document.onload在head标签内写代码..但它似乎不起作用.这是我的代码..
<head>
<script>
document.onload = function () {
alert("Window Loaded...!!");
}
</script>
</head>
Run Code Online (Sandbox Code Playgroud)
但如果我替换window.onload它完美的作品!问题是什么?难道我做错了什么 ??
受JavaScript Closures的启发我尝试使用Func <> Delegate在C#中模拟局部静态变量...这是我的代码..
public Func<int> Increment()
{
int num = 0;
return new Func<int>(() =>
{
return ++num;
});
}
Func<int> inc = Increment();
Console.WriteLine(inc());//Prints 1
Console.WriteLine(inc());//Prints 2
Console.WriteLine(inc());//Prints 3
Run Code Online (Sandbox Code Playgroud)
我很想知道在C#中是否还有其他模拟局部静态变量的方法?谢谢.
请参阅下面的代码
我的问题是:我没有初始化的默认值eId和eName,但仍向属性初始化为默认值.
CLR这样做吗?
class Employee
{
int _empId;
String _eName;
public Employee()
{
// I am not initializing the attributes here
}
public void Disp()
{
Console.WriteLine("Id:: {0} Name:: {1}", _empId, _eName);
}
}
class Program
{
static void Main(string[] args)
{
new Employee().Disp();
}
}
Run Code Online (Sandbox Code Playgroud)