This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
.NET Enumeration allows comma in the last field
i noticed while i was refreshing my memory on c# that with enums, you dont get a complaint from the compiler when you leave a comma after the last variable... EG
enum fruit {
apple,
pear,
watermelon,
}
i was wondering you can do this? shouldnt the compiler say "syntax error: ," or something?
It is part of the C# specification, the compiler is simply following it.
Document: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf
Page 363, Section 19.7
Related
This question already has answers here:
How can I use a reserved keyword as an identifier in my JSON model class?
(3 answers)
How do I use a C# keyword as a property name?
(1 answer)
Closed 3 years ago.
I am currently working on an c# application that uses the spotify api. For the parsing of the Newtonsoft stuff I am using Newtonsoft.Json. But when receiving a track, the json includes a key explicit, and explicit is a keyword. So my question is, if there is a way to give the track class a member called explicit
Use the # prefix to escape reserved keywords.
var #explicit = ...
This question already has answers here:
Can't cast int to bool
(11 answers)
Closed 9 years ago.
I was playing around with type casting earlier today, and came across a something interesting. The C# compiler is unable to cast 0 or 1 to a boolean data type. For example:
bool b = (bool)0;
would return false (if it was able to compile).
There doesn't seem to be any loss of information here, so my question is, is there some specific reason the C# compiler doesn't let you do this?
Because in order for your cast to work, every int would have to be able to be cast to bool, not just 1 and 0. The decision to not allow all integers to be treated as boolean values was done purposefully, to remove the possibility for the kinds of errors this allowance accounts for in languages where it is allowed, e.g. C and C++.
This question already has answers here:
C# Converting delphi TColor to color (Hex)
(2 answers)
Closed 9 years ago.
I have an old application which uses devexpress scheduler, and i am working on new application for it. My problem is in database it has field "LABELCOLOR" of type int. It has values like 536870912, 6610596, 8689404, etc.
Now i need to convert these values to hexadecimal color format using c#, but unable to find any reference how can i do it. I believe these values are integer representation of Delphi colors.
Please guide.
Thanks in advance.
C#: Console.WriteLine(8689404.ToString("X6"));
This question already has answers here:
Can I add an enum to an existing .NET Structure, like Date?
(3 answers)
Closed 8 years ago.
I have one question
How can I specify new value into system enum?
For example, the LoginFailureAction has a enum that define with microsoft in c# how can I get new value into this enum?
Of course, you can't change the default value of a type. The type is the type, and you can't change it.
This question already has answers here:
Closed 13 years ago.
Possible Duplicate:
a curious c# syntax
So I've seen some code around and a few of them use a ? after the type, like this:
private Point? loc = null;
So I'm wondering if Point? is different than Point (can't put a question mark at the end of my sentence or I'll confuse you guys ... :] ). The language I'm using is C# by the way.
T? is a shorthand (in C#) for Nullable<T> - so Point? is another way of writing Nullable<Point> or example.
See sections 1.3 and 4.1 of the C# 3 language spec - and various other places, to be honest - for more details. See the docs for System.Nullable<T> for more information from the framework side of things. Or read chapter 4 of C# in Depth :) (Unfortunately it's not one of the free chapters.)
(This question is bound to be a duplicate, but I don't have the energy to find it right now.)
Point? is the same as Nullable<Point>. It allows you to assign null to value types, such as structs.
It means the type can accept its' value and null.