wakeup Posted January 10, 2006 Posted January 10, 2006 How can I do as c++ #define var var2 In c#? Thanks ___________________ Hip Hop Directo Quote
Administrators PlausiblyDamp Posted January 10, 2006 Administrators Posted January 10, 2006 #define doesn't work like that under C# by design. It may help if you give a bit more detail about what / why you need this feature under C# as there may be a better alternative. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mskeel Posted January 10, 2006 Posted January 10, 2006 You could just declare global consts for your class if you just neede to #define some info into variables? Quote
wakeup Posted January 11, 2006 Author Posted January 11, 2006 I want do it for more easy reference tu array position by example: #define water components[5] Quote
Cags Posted January 11, 2006 Posted January 11, 2006 I have no knowledge of what exactly #define is, since my c++ expertise is practically non-existant. If a #define statement is made at the start of the class and not on the fly, then a property would serve your purpose (given the example you gave), if not then I can't help. Quote Anybody looking for a graduate programmer (Midlands, England)?
wakeup Posted January 11, 2006 Author Posted January 11, 2006 I have given the example #define water components[5] then i can initialise array : for (int i=0;i<MAX;i++) components=x; And then use it : if (water > x) ... And not: if (components[5] > x) ... Quote
Cags Posted January 11, 2006 Posted January 11, 2006 Yes and as I said if water is defined at design-time then a property would suit your purpose, but not if you need to define on the fly. public component water { get { return components[5] } } // and then you can use if(water > x) ... Quote Anybody looking for a graduate programmer (Midlands, England)?
mskeel Posted January 11, 2006 Posted January 11, 2006 The property would definately work and seems to be the closest to what you want to do. Another way of looking at it is instead of using a 5 you could make water = 5 and call the array like components[water]. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.