Re: passing a struct with an array by reference
- From: "Tiberiu Covaci" <tibi AT covaci DOT net>
- Date: Thu, 3 May 2007 21:57:59 +0200
As res is of type MatlabWrap.micDataReturn which is decalred as struct, it means that res is ValueType. Value types gets allocated on stack, and because of that they have to be initialized befor they are first used, because the compiler doesn't make any assumptions about the res initial value. Because your method takes a ref parameter, then the compiler expects that this value (res) is already initialized by you, and because it isn't, then it generate that error message. Why only on LINE 1, and not on LINE 2? If you solve the problem so that LINE 1 will compile, then LINE 2 will be ok as well.
To solve that, just change
MatlabWrap.micDataReturn res;
into
MatlabWrap.micDataReturn res = new MatlabWrap.micDataReturn();
and then everything will be fine.
Regards,
Tibi
MCT, MCPD
"abhiM" <abhi.menon@xxxxxxxxx> wrote in message news:1178214742.322828.87410@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
One more question,
When i compile this function as a part of a bigger project i get the
following error
Use of unassigned local variable 'res' - This is on LINE 1, while
there is no error on LINE2
any idea whats going on?
void function(bool val)
{
MatlabWrap.micDataReturn res;
res.micData = new double[10];
if(val==true)
{
//Run a continuous loop
while (true)
{
getData(ref res); // ---------LINE 1
Thread.Sleep(1000);
}
}
else
{
getData(ref res); //----------LINE 2
}
}
}
Thanks,
AM
PS: btw I changed the 'out's to 'ref' in my previous code example.
.
- References:
- passing a struct with an array by reference
- From: abhiM
- Re: passing a struct with an array by reference
- From: Nicholas Paldino [.NET/C# MVP]
- Re: passing a struct with an array by reference
- From: abhiM
- Re: passing a struct with an array by reference
- From: Nicholas Paldino [.NET/C# MVP]
- Re: passing a struct with an array by reference
- From: abhiM
- passing a struct with an array by reference
- Prev by Date: Re: How would you handle needed "System" class/table/form in application?
- Next by Date: VS2005 - DataGrid.IsSelected( ) broken ?
- Previous by thread: Re: passing a struct with an array by reference
- Next by thread: Re: passing a struct with an array by reference
- Index(es):
Relevant Pages
|