Explicit Variable in C#
What are explicit variable in C#?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
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 Oct 22, 2012, 2:05 AM EDT
These are variables which are given an explicit type when they are declared like this:
string s = "Hello";
In contrast, an implicitly-typed variable is one whose type is inferred by the compiler. Such variables are always declared using the 'var' keyword:
var s = "Hello";
Here 's' is inferred to be a variable of type string because it is being assigned a string.
's' is still strongly typed. If you attempt to subsequently assign it an incompatible value then you will get a compiler error:
s = 3; // compiler error