Today's discussion led me to the question of whether I understand primates and literals correctly.
My understanding is that a literal type is specifically a type that can have a value assigned using a notation that both a person and a compiler can understand without specific type declarations:
var firstName = "John";
My understanding of primitives is that they are essentially elementary data types that the compiler can understand, for example, int:
int age = 25;
... a literal can be non-primitive, such as VB9 support for XML literals. A non-real world example would be if System.Drawing.Point could be assigned literals:
Point somePoint = 2,2; // both X and Y are primitive values, however Point is a // composite value comprised of two primitive values
Finally (and this is a question that, in turn, made me ask the above questions): My understanding is that a type is primitive or literal, there is no direct relation to whether it is a value or a reference type.
For example, System.String is a reference type that supports literals. Custom structures are composite value types that do not support literals.
Is my understanding (if not my explanation) for the most part correct?
Update: Thanks for the great info and conversations! For those who find this, be sure to read the comments, as well as the answers, there will appear some great clarifications, as well as some interesting notes.
btw: this is an ax between which the answer really deserves to get a big green check. I give this, unfortunately, a top-down answer that contains not only a decent answer, but also a lot of clarification and information in the comments. To be fair, there is not a single best answer, there are at least three :)
STW Jan 14 '10 at 17:15 2010-01-14 17:15
source share