D
Danny Tan
Hi folks,
I'm a newbie, trying to pick up C#. This is something, I'm currently working
on for my assignment.
I understand that struct is a "value type". And I'm trying to pass a struct
by reference while instantizing a new Class object.
I can't seems to be able to get it to work. Even after using "ref", it is
still "passed-by-value".
Where did I go wrong?
Regards,
Danny
-------------------------------------------
public struct Bin
{
int j, k;
public Bin(int i, int j)
{
// --- some codes
}
//--- some codes
}
public ClassA
{
Bin bin;
// --- constructor
public ClassA(ref Bin x)
{
bin = x;
}
// --- some codes to change the values of bin
}
public class DriverClass
{
static void Main()
{
Bin bin = new Bin(value1, value2)
// --- instantiate new object passing struct by reference
ClassA NewObject = new ClassA(ref bin);
}
}
I'm a newbie, trying to pick up C#. This is something, I'm currently working
on for my assignment.
I understand that struct is a "value type". And I'm trying to pass a struct
by reference while instantizing a new Class object.
I can't seems to be able to get it to work. Even after using "ref", it is
still "passed-by-value".
Where did I go wrong?
Regards,
Danny
-------------------------------------------
public struct Bin
{
int j, k;
public Bin(int i, int j)
{
// --- some codes
}
//--- some codes
}
public ClassA
{
Bin bin;
// --- constructor
public ClassA(ref Bin x)
{
bin = x;
}
// --- some codes to change the values of bin
}
public class DriverClass
{
static void Main()
{
Bin bin = new Bin(value1, value2)
// --- instantiate new object passing struct by reference
ClassA NewObject = new ClassA(ref bin);
}
}