Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

uning List<struct>


  • Please log in to reply
5 replies to this topic

#1 mrsupe

mrsupe

    New Member

  • Members
  • Pip
  • 6 posts

Posted 10 August 2013 - 06:42 PM

I am not able to use declaration List<...>. with Visual C# 2010 Express.

Where could be a problem?

 



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 11 August 2013 - 03:51 AM

Hi mrsupe, Generics are not supported in the .NET Micro Framework. You can use arrays, jagged arrays, and collections though. Welcome to the Netduino community, Chris

#3 dustmouse

dustmouse

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationEdgewater, CO

Posted 22 December 2013 - 09:34 PM

Without generics, I like to create my own collection class to ensure type safety by including methods for adding and removing objects of a certain type.  The class uses an ArrayList as its internal collection.  The nice thing is that you can ensure that all of the items in the collection are of the expected type.  


Check out my Netduino projects on GitHub.


#4 lifanek

lifanek

    Member

  • Members
  • PipPip
  • 23 posts
  • LocationKatowice, Poland

Posted 12 February 2014 - 04:04 PM

Hi,

 

I would like to do something with an object having it's name/id. For example:

 

module sensor = new module

{

id = 47,

name = "tempSensor"

value = 0,

};

 

later in code I read sensor name (i. e. from UART) and put it to string:

string sensorString = "<sensorname or id>";

 

Now I would like to set some value to it - how can I do that?

<sensorname>.value =  100

 

I was thinking about dictionary (<string, module>) but while its missing in MF I dont know what would be the best method to accomplish that?



#5 perpetualKid

perpetualKid

    Member

  • Members
  • PipPip
  • 20 posts

Posted 14 February 2014 - 06:52 AM

you can use a Hashtable, with the name being the key. Hashtable has untyped object references only, so you need to cast the lookup value somehow like that

((myhashtable[componentname]) as MyModuleType).Value = 100

 

At that time you need to know the type of the module, so best way is if all the module are the same type or derive from a common base class.



#6 lifanek

lifanek

    Member

  • Members
  • PipPip
  • 23 posts
  • LocationKatowice, Poland

Posted 14 February 2014 - 08:08 AM

Hey, I've tried to use object array instead of many individual objects and now can navigate them through array index. I will try your solution also - thanks for help :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.