variable object names
-
I need to create an unknown number of objects, for example DataReaders at runtime. In c# how would I create these names so that the first is dtrFred1 and the next is dtrFred2 etc. Obvisiuosly this will be in the form of a loop. In JScrpit/JavaScript one could use the eval() command, how is this achieved in c# Robert T Turner South Gloucestershire Council
-
I need to create an unknown number of objects, for example DataReaders at runtime. In c# how would I create these names so that the first is dtrFred1 and the next is dtrFred2 etc. Obvisiuosly this will be in the form of a loop. In JScrpit/JavaScript one could use the eval() command, how is this achieved in c# Robert T Turner South Gloucestershire Council
You could hold them in a suitable collection. For instance you can use a
Hashtable
, where the key is "dtrFred1" etc. and the value is the DataReader. Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar The Second EuroCPian Event will be in Brussels on the 4th of September Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way! My Blog
-
I need to create an unknown number of objects, for example DataReaders at runtime. In c# how would I create these names so that the first is dtrFred1 and the next is dtrFred2 etc. Obvisiuosly this will be in the form of a loop. In JScrpit/JavaScript one could use the eval() command, how is this achieved in c# Robert T Turner South Gloucestershire Council
Just to add with what Colin said, I would recommend you look into a class factory for generating your objects. Read this for further information: Abstract factory pattern[^] - Nick Parker
My Blog | My Articles