i'm a newbie in C#. Was in programming many years ago with dBase/
Foxpro/Clipper and some VB.
Perhaps my thinking is still stuck in that kind of mindset..
here's something i'm stuck at..
via the
main(string args), and assuming that the argument passed is ABCD,
how can i create another string variable called ABCD?
is that doable ?
DDD - 13 Mar 2008 08:07 GMT
> i'm a newbie in C#. Was in programming many years ago with dBase/
> Foxpro/Clipper and some VB.
[quoted text clipped - 9 lines]
>
> is that doable ?
You just need to declare a string ABCD in your main scope, no matter
what the parameter value is.
Jon Skeet [C# MVP] - 13 Mar 2008 08:51 GMT
> i'm a newbie in C#. Was in programming many years ago with dBase/
> Foxpro/Clipper and some VB.
[quoted text clipped - 9 lines]
>
> is that doable ?
No. Variable names need to be known at compile-time. Now, take a step
back - what are you actually trying to achieve? Why does the name of
the variable matter to you?

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Jeroen - 13 Mar 2008 08:52 GMT
> via the main(string args), and assuming that the
> argument passed is ABCD, how can i create
> another string variable called ABCD?
>
> is that doable ?
Most likely you want arguments passed into a program to become the
_value_ of a variable, and not the _name_ of a variable. For example,
if your first argument is the name of a client, you might have some
code like this:
string clientName = args[0];
System.Out.WriteLine("Client's name you entered is: " + clientName);
This would generate for your example some output:
Client's name you entered is: ABCD
If you still feel the need to have 'ABCD' where my example has
'clientName', reply with an example with some more meaning than
'ABCD'.
Regards,
Jeroen
DSK Chakravarthy - 13 Mar 2008 09:39 GMT
Dude,
First thing first.. Never ever get confused with Variable names with the
INPUT from the User.
Second thing, Compare apples to apples but not oranges.
Hope you are clear, if not. Forget about the input that is coming from user.
Just declare a variable as abcd. the input will be stored in the args
collection.
HTH
Chakravarthy
> i'm a newbie in C#. Was in programming many years ago with dBase/
> Foxpro/Clipper and some VB.
[quoted text clipped - 9 lines]
>
> is that doable ?
Arne Vajhøj - 15 Mar 2008 04:17 GMT
> i'm a newbie in C#. Was in programming many years ago with dBase/
> Foxpro/Clipper and some VB.
[quoted text clipped - 9 lines]
>
> is that doable ?
No.
But you can achieve a similar effect using Dictionary.
string s = "ABCD";
string ???? = "XYZ";
// use abcd to get "XYZ"
is not possible. But:
Dictionary<string, string> d = new Dictionary<string, string>();
string s = "ABCD";
d.Add(s, "XYZ");
// use d["ABCD"] to get "XYZ"
is possible.
Arne
SharpieNewbie - 04 Apr 2008 08:20 GMT
> > i'm a newbie in C#. Was in programming many years ago with dBase/
> > Foxpro/Clipper and some VB.
[quoted text clipped - 28 lines]
>
> Arne
Thanks all.. the replies are helping me to think further.
Much appreciated!