G
Guest
Without typing it in, which one of the following is invalid and why?
Public Shared ReadOnly mc_SingleQuote_One As Char = Convert.ToChar(&H27)
Public Const mc_SingleQuote_Two As Char = Microsoft.VisualBasic.ChrW(&H27)
Answer:
They are both VALID.
Most people will guess that the 2nd one is invalid because const variables
require a constant value for initialization.
However, the 2nd version works.
The question is...WHY?
It appears that the Microsoft.VisualBasic assembly is automatically calling
the ChrW function once the value of the parameter is changed. Looking at the
documentation, it appears that ChrW is language independent. Ok...but when I
change it to Chr, it also works! Chr DOES take into account the CodePage.
Why are the values produced by these functions allowed to be stored in a
const?
Is the Microsoft.VisualBasic assembly somehow embedded in the IDE?
As far as being, which one is "better"...I would go with the first option
because it can be directly related to its C# counterpart. Furthermore, the
shared variables are only loaded once a call is made into the class
containing them. This provides lazy instantiation, which is ncie, but the
const provides a precompiled value.
Public Shared ReadOnly mc_SingleQuote_One As Char = Convert.ToChar(&H27)
Public Const mc_SingleQuote_Two As Char = Microsoft.VisualBasic.ChrW(&H27)
Answer:
They are both VALID.
Most people will guess that the 2nd one is invalid because const variables
require a constant value for initialization.
However, the 2nd version works.
The question is...WHY?
It appears that the Microsoft.VisualBasic assembly is automatically calling
the ChrW function once the value of the parameter is changed. Looking at the
documentation, it appears that ChrW is language independent. Ok...but when I
change it to Chr, it also works! Chr DOES take into account the CodePage.
Why are the values produced by these functions allowed to be stored in a
const?
Is the Microsoft.VisualBasic assembly somehow embedded in the IDE?
As far as being, which one is "better"...I would go with the first option
because it can be directly related to its C# counterpart. Furthermore, the
shared variables are only loaded once a call is made into the class
containing them. This provides lazy instantiation, which is ncie, but the
const provides a precompiled value.