Problem modifying the value of a boxed value

Schavey
01-25-2004, 01:40 PM
I want to show how to change the value of a member variable in a boxed item.
The C# code works (from a course given by U2U).
My 'translation' in VB.NET doesn't work! I don't get an error, but the value of the
point remains the same!
What am I doing wrong?

Thank you

Pierre Schavey

using System;
using System.Drawing;

namespace BoxingStruct
{ class Class1
{ static void Main()
{
Point p = new Point(10, 20);
object op1 = p;
Console.WriteLine(p);
op1.GetType().GetProperty("X").SetValue(op1, 777, null);
Console.WriteLine(p);
Console.ReadLine();
}
}
}


Imports System.Text
Imports System.Drawing

Module BoxingTest
Sub Go5()
Dim p As Point = New Point(10, 20)
Dim op1 As Object
op1 = p
Console.WriteLine(p)
op1.GetType().GetProperty("X").SetValue(op1, 777, Nothing)
Console.WriteLine(p)
Console.ReadLine()
End Sub

Sub Main()
Go5()
End Sub
End Module

Iceplug
01-25-2004, 04:57 PM
What error are you getting and what line is it on?

Schavey
01-26-2004, 09:03 AM
What error are you getting and what line is it on?

I don't get an error. But with the C# code I can change the value of the X property. This doesn't work in VB.NET, the code does nothing at all.
When I use GetValue("X", Nothing), I can 'read' the value of the property, the same way as in C#.
My question is: why is SetValue working in C# and not in VB.NET?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum