473,383 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

System.reflection question

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
Nov 22 '05 #1
0 1062

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
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...
0
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...
1
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...
10
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.
2
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...
2
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...
3
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 : ...
0
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,...
3
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; .... ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.