By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,458 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,458 IT Pros & Developers. It's quick & easy.

How Can I assign value to Struct variables?

P: n/a
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.

Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
structs are value types and cannot be null. a struct has a default state
such as int default 0.

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #2

P: n/a
You cannot assign null to a struct because it is a value, and not a reference
type.

"脩漏脭脝脫楼" wrote:
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.

Nov 16 '05 #3

P: n/a
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.)

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.