Telmo,
I still try not to use it since it is not a 'real' part of the CLS and
it
is
there for backward compatibility. I accept change and hope to see this
backard compatibility go away in newer versions of VB.
How can it be? CLS is Common Language Specification, which is "the set of
restrictions on the CTS (Common Type System) that ensure interoperability
among language". ChrW is a VB.NET keyword which happens to match the
"(char)" construct in C#. I would not expect ChrW to be part of the CLS any
more then "(char)" to be. The fact it uses a helper function for non
constant parameters is largely immaterial. The helper function simply
ensures that the supplied code point is within the proper range, I
understand that C# simply truncates the integer.
Did you perhaps mean the BCL (Base Class Library)? Does it really matter its
not part of the BCL, considering that Microsoft.VisualBasic is installed
with the framework, effectively making Microsoft.VisualBasic part of the
framework? (Yes it matters if you choose to use Mono, however I understand
that Mono has a Microsoft.VisualBasic assembly).
However! it is NOT there for backward compatibility! It is there as an
integral part of the VB.NET language, just as CType & DirectCast are also an
integral part of the VB.NET language.
You should realize that the contructs in Microsoft.VisualBasic.Compatibility
assembly are there for backward compatibility, which may or may not go away
in newer versions.
The following articles may help you understand the relationship of ChrW and
Convert and other integral parts of the VB.NET language:
http://www.panopticoncentral.net/archive/2004/05/31/1100.aspx
http://www.panopticoncentral.net/archive/2004/06/07/1200.aspx
Funny I thought we were talking about VB.NET!
Hope this helps
Jay
Telmo Sampaio said:
You are right. The VB to MSIL compiler does the work for you (i.e. it
sees
a
constant and therefore does not make a call to Microsoft.VisualBasic)
exactly as you have mentioned.
I still try not to use it since it is not a 'real' part of the CLS and
it
is
there for backward compatibility. I accept change and hope to see this
backard compatibility go away in newer versions of VB.
Telmo Sampaio (not good in VB6)
Telmo,
It uses the Microsoft.VisualBasic.
Which part of ChrW(10) is a constant do you not understand? :-|
Try it yourself, compile the following:
Public Shared Sub Main()
Dim ch As Char = ChrW(10)
End Sub
Use ILDASM to look at the code created:
method public static void Main() cil managed
{
.entrypoint
.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() =
(
01
00 00 00 )
// Code size 6 (0x6)
.maxstack 1
.locals init ([0] char ch)
.language '{3A12D0B8-C26C-11D0-B442-00A0244A1DD2}',
'{994B45C4-E6E9-11D2-903F-00C04FA302A1}',
'{00000000-0000-0000-0000-000000000000}'
// Source File 'C:\Telmo.vb'
//000161: Public Shared Sub Main()
IL_0000: nop
//000162:
//000163: Dim ch As Char = ChrW(10)
IL_0001: ldc.i4.s 10
IL_0003: stloc.0
//000164:
//000165: End Sub
IL_0004: nop
IL_0005: ret
} // end of method Grouping::Main
Where in the above IL do you see Microsoft.VisualBasic?
As I stated before: If the parameter to ChrW is a constant or a
literal,
the
compiler treats it as a constant Char, Microsoft.VisualBasic is not used!!!
Thanks
Jay
It uses the Microsoft.VisualBasic.
Telmo Sampaio
Nikhil,
ChrW(10) is a constant expression!
Microsoft.VisualBasic will not be loaded!
Which also means that ChrW(10) does it without either
Microsoft.VisualBasic.dll or System.dll (mscorlib.dll really).
Only time that ChrW needs to load Microsoft.VisualBasic is when the
parameter is non constant, such as a variable or property.
Hope this helps
Jay
Thanks Jay.
The ChrW is in Microsoft.VisualBasic dll. I don't want to load this
dll
just
for this one function. Because my application is already very slow.
Is there any way to do this using only System.dll?
Thanks.
message
Nikhil,
Have you looked at ChrW?
Dim ch As Char = ChrW(10)
Hope this helps
Jay
Thanks Alex,
Unfortunately I am using VB.Net not C#.
I tried
CType(10, Char)
in VB.Net. But it returned "1".
Nikhil.
did you try
char c = (char)13;
HTH
Alex
Hi all,
How can I convert an integer to its equivalent ascii
character
without
using Microsoft.VisualBasic dll or any other dll(I want to
reference
only
System.dll).
Thanks.
-Nikhil