David,
| For instance, Convert.ToInt32 will do what AscW does, but
Consider the case where you pass a literal or constant to AscW or ChrW.
In the case of a literal or constant AscW & ChrW are evaluated at compile
time, there is no function called! Only "pure" inline IL opcodes!
In the case of a char or integer variables AscW is emitted as IL code.
In the case of a Char variable ChrW is emitted as a library call, even then
its a library of .NET functions. My understanding is so as to ensure
negative values are converted into their corresponding "unsigned value".
In the case of String variables are AscW & ChrW is emitted as a library
call, even then its a library of .NET functions. As you stated, this is to
return the first character.
See below for IL code:
//000065:
//000066: Dim ch As Char
//000067: Dim charCode As Integer
//000068: Dim s As String
//000069:
//000070: ch = ControlChars.Lf
IL_0016: ldc.i4.s 10
IL_0018: stloc.0
//000071:
//000072: s = ch
IL_0019: ldloc.0
IL_001a: call string
[Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.StringType: :FromChar(char)
IL_001f: stloc.2
//000073:
//000074: charCode = AscW(s)
IL_0020: ldloc.2
IL_0021: call int32
[Microsoft.VisualBasic]Microsoft.VisualBasic.Strings::AscW(string)
IL_0026: stloc.1
//000075:
//000076: charCode = AscW(ch)
IL_0027: ldloc.0
IL_0028: stloc.1
//000077:
//000078: ch = ChrW(charCode)
IL_0029: ldloc.1
IL_002a: call char
[Microsoft.VisualBasic]Microsoft.VisualBasic.Strings::ChrW(int32)
IL_002f: stloc.0
//000079:
//000080: s = ChrW(charCode)
IL_0030: ldloc.1
IL_0031: call char
[Microsoft.VisualBasic]Microsoft.VisualBasic.Strings::ChrW(int32)
IL_0036: call string
[Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.StringType: :FromChar(char)
IL_003b: stloc.2
//000081:
| You could write your own AscW and ChrW functions using 'pure' .NET code,
but
| what's the point? (very well tested versions already exist)
Do people really believe that AscW & ChrW are not "pure" .NET code?
What an odd mis-conception people must have of the framework. :-|
Hope this helps
Jay
"David Anton" <Da********@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
|I agree. AscW and ChrW are reliable functions that are the most elegant
way
| to do this. For instance, Convert.ToInt32 will do what AscW does, but you
| will have to ensure you're passing exactly one character - AscW takes care
of
| that for you by only looking at the first character if you pass a string.
|
| You could write your own AscW and ChrW functions using 'pure' .NET code,
but
| what's the point? (very well tested versions already exist)
| --
| David Anton
|
www.tangiblesoftwaresolutions.com
| Home of:
| Clear VB: Cleans up outdated VB.NET code
| Instant C#: Converts from VB.NET to C#
| Instant VB: Converts from C# to VB.NET
| Instant J#: Converts from VB.NET to J#
|
|
| "Mattias Sjögren" wrote:
|
| > >I would really rather use the "dot-nettified" syntax rather than
digging
| > >global functions out of Microsoft.VisualBasic.
| > >
| > >Anyone know the newfangled way to achieve the same results?
| >
| > Well if you really want to you can use the System.Convert class.
| >
| > But I would think twice before using that over ChrW/AscW. They are
| > compile-time evaluated expressions that result in code that's more
| > efficient than any function call ever can be.
| >
| >
| > Mattias
| >
| > --
| > Mattias Sjögren [MVP] mattias @ mvps.org
| >
http://www.msjogren.net/dotnet/ |
http://www.dotnetinterop.com
| > Please reply only to the newsgroup.
| >