How Can I assign value to Struct variables?

  • Thread starter Thread starter Ñ©ÔÆÓ¥
  • Start date Start date
Ñ

Ñ©ÔÆÓ¥

Hi,all

I have a trouble about struct variable,the detail is :

I define a new struct which name ServiceProperty,then I declare a variable
like this:

ServiceProperty instService = null;

but compile throw error: error CS0037: ÎÞ·¨½« NULL ת»»³É
¡°ServiceProperty¡±£¬ÒòΪËüÊÇÒ»ÖÖÊýÖµÀàÐÍ


How shoud I do? please give me some tips,thank you very much.
 
structs are value types and cannot be null. a struct has a default state
such as int default 0.

Regards,
Jeff
 
You cannot assign null to a struct because it is a value, and not a reference
type.
 
Perhaps if you explained further what a ServiceProperty is and what you
use it for. (I ask because I suspect that it should be a class, not a
struct, but without further information I can't be sure.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top