Reading value from a variabile
-
Well, this sounds like a homework question. Why would anybody else want to use variable names like that? If you really wanted to use *indexed* versions of the variable, you would use an array of some description.
Deja View - the feeling that you've seen this post before.
Actually it's not a homework, and I've tried with arrays and arraylists but I need another way that this could be done.
Do your best to be the best
-
Hi, I have a small question. I have some variables with almost the same name. For example:
string message_108 = "fngfh"; string message_109 = "88"; string message_110 = "22"; ..... string message_200 = "ffb";
All I want is to create some kind of method which receives the number of the message (e.g. 110) and that returns the description(value) of that message (message_110). Can you give me any suggestions.Do your best to be the best
Rework it into an array or hashtable.
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
-
Actually it's not a homework, and I've tried with arrays and arraylists but I need another way that this could be done.
Do your best to be the best
karkster wrote:
I've tried with arrays and arraylists but I need another way that this could be done
Then we need to look at the bigger picture, because at the moment what you are doing does not make any sense.
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
-
karkster wrote:
I've tried with arrays and arraylists but I need another way that this could be done
Then we need to look at the bigger picture, because at the moment what you are doing does not make any sense.
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
Let me put it in another form. I want to access a Property of a class, but I have the name of the property in a string.
Do your best to be the best
-
Let me put it in another form. I want to access a Property of a class, but I have the name of the property in a string.
Do your best to be the best
Use reflection. There are numerous examples on Google on how to do this. Hint - look at
GetType().GetProperty(...).GetValue(...)
Deja View - the feeling that you've seen this post before.
-
Let me put it in another form. I want to access a Property of a class, but I have the name of the property in a string.
Do your best to be the best
Have you thought of using reflection? Reflection won't work with local variables, but will work with properties.
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
-
Use reflection. There are numerous examples on Google on how to do this. Hint - look at
GetType().GetProperty(...).GetValue(...)
Deja View - the feeling that you've seen this post before.
Ya beat me to it!
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
-
Have you thought of using reflection? Reflection won't work with local variables, but will work with properties.
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
:) Thanks. It works with Reflection.
Do your best to be the best
-
Ya beat me to it!
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
:-D
Deja View - the feeling that you've seen this post before.
-
Hi, I have a small question. I have some variables with almost the same name. For example:
string message_108 = "fngfh"; string message_109 = "88"; string message_110 = "22"; ..... string message_200 = "ffb";
All I want is to create some kind of method which receives the number of the message (e.g. 110) and that returns the description(value) of that message (message_110). Can you give me any suggestions.Do your best to be the best
Use reflection. Because you are using members you will have to use FieldInfo not PropertyInfo. Of course, like others have mentioned, I would use a hash instead of members.
File Not Found