Searching Effort:
- Google:
- Stackoverflow:
And some more I do not remember...
Preconception: Every "built-in type" in c# (such as int
, float
, char
etc.) is a class, and every class in C# inherits from the Object
class. Therefore, every "built-in type" inherits from the Object
class.
With that preconception in mind, I would assume that to set a double
variable, for example, I would need to set some properties using the "normal" syntax. Here is what I mean:
double number = new double();
number.leftSide= 5;
number.rightSide = 23;
Console.Write(number);
// Output:
// 5.23
But C# has a special, equivalent syntax for creating a double
variable (in a way that it would do what I tried to do above, not that the code above will actually work):
double number = 5.23;
The compiler understands that the floating point separates the number into two: 5 and 23.
My question is if I can do the same with my own classes. For example, if I have my own Time
class (and it is just an example, so please do not suggest to use built-in time classes), I would want to have the option to instantiate it like so:
Time time = 10:25;
And the compiler would understand that the colon separates the number into hours and minutes (which are, I assume, properties I need to create in the Time
class).
I have heard about Roslyn CTP but I am looking for a simpler, built-in way, of doing what I have described.
Can I do it?