What is the difference between variable
and string
in c#
Why the c#
is supporting only this
var data = GetData("");
Why not this?
string data = GetData("");
Or it will support both? Which one is better to use ? How it is implemented?
private DataTable GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["ProjectConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection cn = new SqlConnection(conString))
{
using (SqlDataAdapter da = new SqlDataAdapter())
{
cmd.Connection = cn;
da.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
da.Fill(dt);
return dt;
}
}
}
}
GetData()
returns string, thenvar = string
in this caseGetData
in this case? Without knowing what it's declared to return, we can't answer the question.var
do?" then you should read msdn.microsoft.com/en-us/library/bb383973.aspxdatatable
is it fair enough to usevar