I have two code snipets, one in VB and the other in C#. Why does the visual
basic example not change the structure member "x", but the C# code does? I
need the visual basic code to work as I am a visual basic coder, but I don't
know what is wrong. Is there a bug in visual basic.net? Please help!
'VB Code
Imports System
Imports System.Reflection
Structure Foo
Public x As Integer
End Structure
Class Test
Shared Sub Main()
Dim f As New Foo
f.x = 10
Dim fi As FieldInfo = GetType(Foo).GetField("x")
Dim o As Object = f
fi.SetValue(o, 3)
f = CType(o, Foo)
Console.WriteLine(f.x)
End Sub
End Class
//C#
using System;
using System.Reflection;
struct Foo
{
public int x;
}
Class Test
{
static void Main()
{
Foo f = new Foo();
f.x = 10;
FieldInfo fi = typeof(Foo).GetField("x");
object o = f;
fi.SetValue (o, 3);
f = (Foo)o;
Console.WriteLine (f.x);
}
}
--
Erol 2 1822
See http://thedotnet.com/howto/work325581.aspx
--
Carlos J. Quintero
The MZ-Tools all-in-one add-in, now for .NET: http://www.mztools.com
"Erol" <Er**@discussions.microsoft.com> escribió en el mensaje
news:D3**********************************@microsof t.com... I have two code snipets, one in VB and the other in C#. Why does the visual basic example not change the structure member "x", but the C# code does? I need the visual basic code to work as I am a visual basic coder, but I don't know what is wrong. Is there a bug in visual basic.net? Please help!
'VB Code Imports System Imports System.Reflection
Structure Foo Public x As Integer End Structure
Class Test
Shared Sub Main() Dim f As New Foo f.x = 10
Dim fi As FieldInfo = GetType(Foo).GetField("x")
Dim o As Object = f fi.SetValue(o, 3) f = CType(o, Foo)
Console.WriteLine(f.x) End Sub End Class
//C# using System; using System.Reflection;
struct Foo { public int x; }
Class Test { static void Main() { Foo f = new Foo(); f.x = 10;
FieldInfo fi = typeof(Foo).GetField("x");
object o = f; fi.SetValue (o, 3); f = (Foo)o;
Console.WriteLine (f.x); } }
-- Erol
Thank-you very much Carlos, it worked
"Carlos J. Quintero [.NET MVP]" wrote: See http://thedotnet.com/howto/work325581.aspx
--
Carlos J. Quintero
The MZ-Tools all-in-one add-in, now for .NET: http://www.mztools.com
"Erol" <Er**@discussions.microsoft.com> escribió en el mensaje news:D3**********************************@microsof t.com...I have two code snipets, one in VB and the other in C#. Why does the visual basic example not change the structure member "x", but the C# code does? I need the visual basic code to work as I am a visual basic coder, but I don't know what is wrong. Is there a bug in visual basic.net? Please help!
'VB Code Imports System Imports System.Reflection
Structure Foo Public x As Integer End Structure
Class Test
Shared Sub Main() Dim f As New Foo f.x = 10
Dim fi As FieldInfo = GetType(Foo).GetField("x")
Dim o As Object = f fi.SetValue(o, 3) f = CType(o, Foo)
Console.WriteLine(f.x) End Sub End Class
//C# using System; using System.Reflection;
struct Foo { public int x; }
Class Test { static void Main() { Foo f = new Foo(); f.x = 10;
FieldInfo fi = typeof(Foo).GetField("x");
object o = f; fi.SetValue (o, 3); f = (Foo)o;
Console.WriteLine (f.x); } }
-- Erol This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Terminal882003 |
last post by:
Hi,
Here I have a question about MSCommLib. I need to dynamically add
activeX controls that requires run-time license for MSCommLib. The
following is the actual code:
AxMSCommLib.AxMSComm...
|
by: Erol |
last post by:
I have two code snipets, one in VB and the other in C#. Why does the visual
basic example not change the structure member "x", but the C# code does? I
need the visual basic code to work as I am a...
|
by: Brian |
last post by:
I've looked through the previous posts on this one and have verified
permissions and location of my Dlls, but I am still getting an
exception when I try to Load an assembly.
The directory where...
|
by: Qwert |
last post by:
Hello,
is it correct that if a type (System.Type) is a value (.IsValueType=True)
and not primitive (.IsPrimitive=False), that type is a structure?
Thanks.
|
by: Gujju |
last post by:
Hi all,
I m new to this class..
With System.Reflection... u can create run time objects for a specified
class in a assembly...
Now if once the Assembly is loaded in the memory then does...
|
by: Doug |
last post by:
Hi,
I have two questions about Reflection. One I think I know the answer
to but will ask anyway.
1) I can delve into a component or executable and get all the way to
the method within a...
|
by: Olivier BESSON |
last post by:
Hello,
I have a web service of my own on a server (vb.net). I must declare it with
SoapRpcMethod to be used with JAVA.
This is a simple exemple method of my vb source :
...
|
by: Frank Uray |
last post by:
Hi all
I have a problem with loading a assembly ...
I am trying to do the following:
- I have a directory with a dll (assembly) in it (not the currect dir.)
- I am trying to load this assembly,...
|
by: groovyjman21 |
last post by:
Hi, I am using FXCop on my c# project and it is complaining about
signing the assembly with a strong name key. All the documentation I
can find says to do:
using System.Reflection;
....
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |