Advice about variable type

This is a discussion on Advice about variable type within the C# Programming forums, part of the General Programming Boards category; Hey all My goal is to create a class with a method for sending a register name and value. In ...

  1. #1
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,384

    Advice about variable type

    Hey all

    My goal is to create a class with a method for sending a register name and value.

    In C I would use a typedef + enum to create a list of registers to be sent serially using a function.

    Code:
    typedef enum RegList Registers;
    ...
    SendPacket( Registers Address, unsigned int Data)
    I'd like to know what some of the strategies that are used in C# to create these register names to passed into the method. Would a public enum in the method's class be the best way? Is there another neater way I'm missing?
    Fact - Beethoven wrote his first symphony in C

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,467
    See c# structs.

    An enum seems too restrictive. I'm not sure what registers means in the context of your program. But seeing the word address associated with them, indicates to me you may want to eventually add, change or remove addresses from your program. With a struct you can create the functionality to do this at runtime.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,384
    Thanks for the reply - The "registers" are on an external device.

    I'm sending a frame via RS232 which has a register name and some data that I want to send to it.

    I was originally going to use a switch statement to find what register needs to be modified (using an enum), and then constructing the appropriate string to modify it.

    Now I'm not using any subroutine to send these packets (yucky, I know).

    Now that I have had time to think about it, I think that a class is a better way to go. The class could have
    Constant command string (identifies what register is being modified in frame)
    Int16 data (the data is always a 16 bit integer)
    Send data (a method for sending the information)

    I'm primaraly a C programmer, so OOP does not come naturally to me - Any advice is very much appreciated!
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is this variable type????
    By Daniel.Blesener in forum C Programming
    Replies: 5
    Last Post: 06-29-2012, 10:09 AM
  2. Replies: 2
    Last Post: 05-14-2011, 09:26 PM
  3. Need advice on umm.. variable number of variables haha.
    By ljrobison in forum C++ Programming
    Replies: 9
    Last Post: 02-21-2010, 07:32 PM
  4. Newbie variable advice
    By 182 in forum C++ Programming
    Replies: 12
    Last Post: 02-15-2006, 05:08 PM
  5. variable type char to variable type int
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 07-15-2002, 08:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21