By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,341 Members | 1,395 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,341 IT Pros & Developers. It's quick & easy.

Equivalent of Fixed

P: n/a
I was using .Net Reflector to look at some methods in the String class
and found this one:

Friend Sub AppendInPlace(ByVal value As Char*, ByVal count As Integer,
ByVal currentLength As Integer)
Dim local1 As Char*
Fixed local1 = AddressOf Me.m_firstChar
Dim num1 As Integer
For num1 = 0 To count - 1
local1((currentLength + num1)) = value(num1)
Next num1
End Fixed
Me.SetLength((currentLength + count))
Me.NullTerminate
End Sub

In C# is shows like this:

internal unsafe void AppendInPlace(char* value, int count, int
currentLength)
{
fixed (char* local1 = &this.m_firstChar)
{
for (int num1 = 0; num1 < count; num1++)
{
local1[currentLength + num1] = value[num1];
}
}
this.SetLength(currentLength + count);
this.NullTerminate();
}
fixed is apparently a statement in C# but I was curious about its use
in VB.Net. Specifically the Fixed .. End Fixed construct. This is
obviously invalid as it wont even compile in the IDE. So why is
Reflector showing its output? How would the C# code be translated to
VB.Net?

Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Chris,

"Chris Dunaway" <du******@gmail.com> schrieb:
I was using .Net Reflector to look at some methods in the String class
and found this one:

Friend Sub AppendInPlace(ByVal value As Char*, ByVal count As Integer,
ByVal currentLength As Integer)
Dim local1 As Char*
Fixed local1 = AddressOf Me.m_firstChar
Dim num1 As Integer
For num1 = 0 To count - 1
local1((currentLength + num1)) = value(num1)
Next num1
End Fixed
Me.SetLength((currentLength + count))
Me.NullTerminate
End Sub

In C# is shows like this:

internal unsafe void AppendInPlace(char* value, int count, int
currentLength)
{
fixed (char* local1 = &this.m_firstChar)
{
for (int num1 = 0; num1 < count; num1++)
{
local1[currentLength + num1] = value[num1];
}
}
this.SetLength(currentLength + count);
this.NullTerminate();
}
fixed is apparently a statement in C# but I was curious about its use
in VB.Net. Specifically the Fixed .. End Fixed construct. This is
obviously invalid as it wont even compile in the IDE. So why is
Reflector showing its output? How would the C# code be translated to
VB.Net?


Something similar to 'fixed' can be archieved using
'System.Runtime.InteropServices.GCHandle.Alloc' and
'System.Runtime.InteropServices.GCHandle.AddressOf PinnedObject'. However,
as VB.NET doesn't support pointers the way C# does, a direct equivalent to
the C# code for VB.NET doesn't exist.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2

P: n/a
I thought so. I was just curious as to why Reflector was outputting it
that way.

Nov 21 '05 #3

P: n/a
"Chris Dunaway" <du******@gmail.com> schrieb:
I thought so. I was just curious as to why Reflector was outputting it
that way.


Mhm... I think it's better that Reflector outputs this code instead of
saying "No VB.NET version available" ;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.