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 = stringin this caseGetDatain this case? Without knowing what it's declared to return, we can't answer the question.vardo?" then you should read msdn.microsoft.com/en-us/library/bb383973.aspxdatatableis it fair enough to usevar