1

I wonder if anyone can explain how the System.double is different from System.Double and how these differences are constructed in code.

if one looks at the Class:

public struct Double : IComparable, IFormattable, IConvertible, IComparable<Double>, IEquatable<Double>

from: https://referencesource.microsoft.com/#mscorlib/system/double.cs,1a65cbdb09544ba1

There is no clarity between the double and Double Types.

Using Visual Studio 2015, it is recommended that one uses the double key word instead of Double as the conversion is less.

If I were to write a custom Data Type and derive from double, for example, would constructing it by dynamic be enough to get the ball rolling.

It baffles me at how .NET has derived the base Data Types.

EDIT: A search on the net shows there is a lot of confusion on this topic. For example:

using System;

public class QBit : IComparable, IFormattable, IConvertible
{

internal _qbit

public string Value { get { return _qbit; }

public QBit()
{
_qbit = "1978";
}

}

In another class:

using System;

using qbit = QBit;

public class Spinstate
{

internal _state

public string Value { get { return _state; }

public QBit()
{
qbit = new QBit ();
_state = qbit.Value;
}

}

Is not the same as a Keyword, this is an Alias. How to declare a Keyword?

EDIT: A KEYWORD is defined as:

Keywords are predefined reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. For example, @if is a legal identifier but if is not because it is a keyword.

The Keyword 'double' is defined as follows:

The double keyword signifies a simple type that stores 64-bit floating-point values. The following table shows the precision and approximate range for the double type.

The Type is as specified by the IEEE 754 standard, which is a binary64 Double precision floating-point format - Still, we are no closer to Defining a Keyword in Code and more importantly "and how they are constructed"

Alexei Levenkov
  • 94,391
  • 12
  • 114
  • 159
Rusty Nail
  • 2,445
  • 3
  • 28
  • 50
  • `System.double` doesn't exist, it's just a keyword `double`. And note that `double` isn't part of .NET, just C# and any other languages that happen to use it, presumably all as aliases for `System.Double`. – chris Jan 22 '17 at 03:50
  • Standard `string vs. String` question covers all types you are interested in. If you need more specific duplicate - http://stackoverflow.com/questions/3951224/is-there-a-meaningful-difference-between-double-and-double-in-net (use search engine - like Bing - https://www.bing.com/search?q=c%23%20double%20vs%20double%20site%3Astackoverflow.com or Google to read more on the topic). – Alexei Levenkov Jan 22 '17 at 03:53
  • Closing original question as duplicate turned out to be very constructive (as designed to work on SO) - you've edit post and provided information why it is not duplicate (also it sounds like you actually asking about something different altogether) - thanks for that. Since it is clearly no longer duplicate I'm re-openeing the question. Please consider [edit] title of the post to align with the post. – Alexei Levenkov Jan 22 '17 at 05:24
  • Yes, it is very hard to comprehend. Sorry. Unfortunately body of the post makes it even more confusing - you ask about "how `double` is different from `System.Double`" even when you know they refer to the same thing, you already show how data types are constructed (with couple samples of classes), and ask how to define keywords when you know that they are "*predefined* reserved identifiers that have special meanings to the compiler". I understand that you have a lot of context for the post in your head, but it is hard to others to see that in the post. – Alexei Levenkov Jan 22 '17 at 05:34
  • @AlexeiLevenkov - Maybe you could rip into your resources at **Microsoft** and let us know? – Rusty Nail Jan 22 '17 at 06:02
  • Your question already explains that "Defining a Keyword in Code" is not possible because "Keywords are *predefined* reserved identifiers" (along with link to complete list). I'm completely lost on what kind of information you are looking for. – Alexei Levenkov Jan 22 '17 at 06:07
  • 1
    Note that if you simply looking at how the list of keywords is defined in compiler you can look at source code https://roslyn.codeplex.com/ to find it out (compiler internals are way outside of my knowledge - so no idea where exactly table of keywords would be) – Alexei Levenkov Jan 22 '17 at 06:10
  • @AlexeiLevenkov - Existing Keywords are "*predefined reserved identifiers*", yes, I see that. But Creating a new Keyword, this is not possible? Can we not create a new Keyword and add this to the list of "*predefined reserved identifiers*"? Thanks for the link +1 – Rusty Nail Jan 22 '17 at 06:29
  • 1
    Extending the list of keywords may not be as easy as 'extension methods' (probably not possible at all unless you are planning to extend the C# language itself) – Thangadurai Jan 22 '17 at 06:36
  • 1
    @GoogleInc I've changed title of the post to what I believe you are looking for and added "no" as an answer. – Alexei Levenkov Jan 22 '17 at 06:37

1 Answers1

1

No, it is not possible to create new keywords in C# (and most other languages) as those are predefined by language authors. The only way to add one is to convince language authors to include it in language specification.

Alexei Levenkov
  • 94,391
  • 12
  • 114
  • 159
  • Thank You - Searching the Roslyn code for an example to post. I have an idea for a data type that may help in my Coding. Would be nice to implement it on a Global Scale. – Rusty Nail Jan 22 '17 at 06:39