RE: Embedding a Variable in a string C# Dotnet

  • From: "Sina Bahram" <sbahram@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 7 Jan 2009 18:15:34 -0500

If you absolutely need to do this, which I question the need of in this
example, the methodology you wish to use is called reflection, if you look
up reflection you'll get exactly what you'd like.

Take care,
Sina 

________________________________

From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Jeff Berwick
Sent: Wednesday, January 07, 2009 6:13 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Embedding a Variable in a string C# Dotnet


Hi Listers,
 
Please bare with me while I attempt to explain what I want to do.
 
I want to build a string that has a variable name inside it.  Then, I want
to send that string to a function which will recognise the variable name,
embedded din the string, and replace it with its value.  Is this possible?
 
By way of an illustration:
 
private void stuff()
{
string firstname;
string lastname;
string result;
 
result = buildString();
MessageBox.Show(result.ToString());
}
 
private string buildString()
{
return "Here is the string with the two variables - firstname and lastname";
}
 
I also tried putting {} around the variable name but, as expected that
didn't work.  Any suggestions on an elegant solution?
 
Thx,
Jeff

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: