Reputation: 4673
Just imagine this simple situation:
int temperature = 20;
is there any possibility to give a dynamic parameter name?? Like for example (I know that doesn't work, just to get the idea) :
int Array[1].ToString() = 20;
Thank you! Cheers Chris
Upvotes: 0
Views: 814
Reputation: 84
try this
using System;
class Program
{
static void Foo(dynamic duck)
{
duck.Quack(); // Called dynamically
}
static void Foo(Guid ignored)
{
}
static void Main()
{
// Calls Foo(dynamic) statically
Foo("hello");
}
}
and follow that link Link1
Upvotes: 0
Reputation: 715
Not sure if this is what you are looking for but you can play with the dynamic/Expando objects in C# 4
Upvotes: 2
Reputation: 245449
No. Not in C#. The closest you could get would be to use a Dictionary<string, object>
:
var variables = new Dictionary<string, object>();
variables.Add(Array[1].ToString(), 20);
But not only does that involve casting each time you need to retrieve the value, but it will also cause boxing/unboxing.
All told, I certainly wouldn't recommend it.
Upvotes: 2