Help with "structs"
#1
Posted 08 November 2013 - 02:28 PM
- Claiskessed and kekzenevito like this
#2
Posted 08 November 2013 - 02:59 PM
You can delete '=new byte[4]' to fix '...MAX6651_DATA.tachos': cannot have instance field initializers in structs' compiler error. Alternatively, replace 'struct' with 'class', then you can leave the initializer there.
If that does not help, please show the exact error you are getting...
#3
Posted 20 December 2013 - 05:01 PM
myFan.dac = 100;
to assign the dac element the value 100....
When you access a property on a struct, it returns a copy of that value. When you attempt to change the value, you are changing the value of the copy, not the original. As far as I know, if you want to change the value, you need to create a new struct with the new value, copying the other values from the original struct.
If there isn't a compelling reason to make [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]MAX6651_DATA a struct, then like CW2 suggested, you can just change it to a class. One reason for keeping it as a struct is if you are going to be creating a large volume of them. Structs have a smaller memory footprint than classes (which store additional overhead).[/color]
Check out my Netduino projects on GitHub.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users