Mimi wrote:
Does anyone know how to tell if a structure exists in an expression? If I
have a structure
struct hits {
uint numhits,maxhits;
char ch;
}
public void test( )
{
hits result, oldresult;
if (result) // in C/C++ I can test if result exists.
oldresult = result;
}
How do I find out if result has been set or not if the value is not defined?
AFAIK this wouldn't work in C either. Your code is equivalent to:
if (result == 0)
which would have to cast a struct to a boolean in order to do the
comparison. My (embedded, but ASNSI-compliant) C compiler barfs at this
with the message "Scalar expression required".
From the C# programmer's reference:
"When you create a struct object using the new operator, it gets created
and the appropriate constructor is called. Unlike classes, structs can
be instantiated without using the new operator. If you do not use new,
the fields will remain unassigned and the object cannot be used until
all of the fields are initialized."
HTH,
-rick-