Dynamic Variable Naming

This is a discussion on Dynamic Variable Naming within the C# Programming forums, part of the General Programming Boards category; Hi, Is there any way in c# that you can name custom objects on the fly? I 'm trying to ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    21

    Question Dynamic Variable Naming

    Hi,

    Is there any way in c# that you can name custom objects on the fly?

    I 'm trying to create a method which checks if a "Workload" object exists against a "User" object, and if not it creates one.

  2. #2
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    I'm not sure what you mean, but I think your looking for some kind of map/dictionary type of structure ?

    C# has a collection class called NameValueCollection. It's similar to an STL map if thats what your looking for.

    NameValueCollection Class (System.Collections.Specialized)

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Not until C# 4.0 and "Dynamic objects" is released.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    You can also use a Dictionary<string, MyClass> (or, if you want objects of different types, Dictionary<string, object> ).
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    Code:
    WeatherStation station, DateTime predictionDate
    can we define the variables in c sharp like this?i am looking through some codes here and while compiling got the error saying"are you missing a using directive or an assembly reference cs0246"
    and it is showing error for this variables. I tried to remove it but the program have used the variable name station and predictionDate in the program. So can you help me out?

  6. #6
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    You can if you define them somewhere and add a semicolon instead of the comma.

    Code:
    WeatherStation station;
    DateTime predictionDate;
    Spidey out!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List and Dynamic Memory Allocation
    By girly_engineer in forum C Programming
    Replies: 4
    Last Post: 04-18-2009, 11:50 AM
  2. C variable
    By webstarsandeep in forum C Programming
    Replies: 1
    Last Post: 10-23-2008, 01:26 AM
  3. Static Local Variable vs. Global Variable
    By arpsmack in forum C Programming
    Replies: 7
    Last Post: 08-21-2008, 03:35 AM
  4. float/double variable storage and precision
    By cjschw in forum C++ Programming
    Replies: 4
    Last Post: 07-28-2003, 06:23 PM
  5. Beginner question
    By Tride in forum C Programming
    Replies: 30
    Last Post: 05-24-2003, 08:36 AM

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