How to get an entire struct out of a class?
Hi Simon & Mykonian
Here is some code to help shed some light on my issue. It appears I can access the struct but all their values are zero when I access them from Cross.Process so I assumed I was trying to improperly access them. Any ideas?
class Form1()
{
public struct crossvars
{
public uint bases;
public double step;
public double baselo;
public double basehi;
public byte SLOPE;
}crossvars myCrossVars;
public crossvars GetBasehi
{
get
{
return myCrossVars;
}
set
{
}
}
void someMethod()
{
Cross myCrossObj = new Cross();
Console.WriteLine("basehi_before_passingto_CROSS={0}", myCrossVars.basehi);
myCrossObj.Process(LeftWheel, MinSampleSize, FileCount, steps);
Console.WriteLine("basehi_backfrom_passingto_CROSS={0}", myCrossVars.basehi);
}
}
class Cross()
{
void Process()
{
//try to create obj and access struct thru property Get
Form1 myStructObj = new Form1();
Console.WriteLine("basehi_in Cross.Process_Get={0}",myStructObj.GetBasehi.basehi);
//try another way to access the struct create obj for struct itself
Form1.crossvars myObj = new Form1.crossvars();
Console.WriteLine("basehi_in Cross.Process_structobject={0}",myObj.basehi);
}
}
The struct member myCrossVars.basehi is being set thru a updn control in Form1.
The following output resulted
(Form1) basehi_before_passingto_CROSS=32.9
(Cross) basehi_in Cross.Process_Get=0
(Cross) basehi_in Cross.Process_structobject=0
(Form1)basehi_backfrom_passingto_CROSS=32.9
end output
As you can see the value being returned for basehi from Form1 class is 0(zero) yet the value is correct before and after passing to Cross.Process. I can't get the correct values when attempting to access the struct from the Cross class. The accessibility is set to public on the struct decleration, the propety and members. Any ideas?
Thank you
db
bilnaadPosted Jan 10, 2005, 6:58 AM
doug 0Posted Jan 8, 2005, 12:46 AM
bilnaadPosted Jan 7, 2005, 8:04 PM
doug 0Posted Jan 7, 2005, 3:27 PM
bilnaadPosted Jan 7, 2005, 1:43 PM
doug 0Posted Jan 7, 2005, 11:32 AM
bilnaadPosted Jan 7, 2005, 2:53 AM