Hi friends,
I want to know that if we have two variable like as
var v="10";
object o="10"
then what is the difference between both of them please give any explanation?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jan 12, 2012, 6:32 AM EST
Pardeep Malik129 reputationPosted Jan 12, 2012, 9:44 PM EST
but object is a root data type
we can put a "var" type variable in object type
it supports implicit casting in that case
as
var a=10;
object b=a;
there is no need to cast
but if we retrive this value
we have to cast with var type
as
var c=(var)b;
VulpesRank #55 · 29.2K reputationPosted Jan 12, 2012, 11:53 PM EST
Pardeep Malik129 reputationPosted May 11, 2012, 10:19 PM EDT
you are right.
we can put an object to var and also a var to object.
it tried both
as
{
static void Main(string[] args)//var a = "10";
//object b;
//b = a;
//var c = b;
//Console.WriteLine(c);
//Console.ReadKey();O
var b = a;
object c = b;
Console.WriteLine(c);
Console.ReadKey();
}
both gives same result with out an error
bject a="10";