Explicit Variable in C#
What are explicit variable in C#?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Oct 22, 2012, 6:05 AM
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