为字符串创建动态名称 [英] Create dynamic Name for string
问题描述
我想从我的数据库的一行创建一个字符串,但是对于每一行,我需要一个新的
字符串和变量的新名称。
例证:
int i = myRow [" ID"];
string varName =" news";
createNameVar = varName + i;
但是我不能在C#中评估这个,还有字符串news1,new2,...,newsN不要
存在。
我怎么能这样做?
I want create a string from a row of my db, but for each rows i need a new
string and a new name for the variable.
exemple:
int i = myRow["ID"];
string varName = "news";
createNameVar = varName + i;
but i can''t eval this in C#, also the strings news1, new2,...,newsN don''t
exist.
How i can do that?
推荐答案
KaHuNa< ka **** @ quickemail.de>写道:
KaHuNa <ka****@quickemail.de> wrote:
我想从我的数据库的一行创建一个字符串,但对于每一行,我需要一个新的
字符串和变量的新名称。
例如:
int i = myRow [" ID"];
string varName =" news";
createNameVar = varName + i;
我怎么能这样做?
I want create a string from a row of my db, but for each rows i need a new
string and a new name for the variable.
exemple:
int i = myRow["ID"];
string varName = "news";
createNameVar = varName + i;
but i can''t eval this in C#, also the strings news1, new2,...,newsN don''t
exist.
How i can do that?
为什么需要变量的新名称?为什么不使用数组呢?
-
Jon Skeet - < sk *** @ pobox.com>
如果回复该组,请不要给我发邮件
Why do you need a new name for the variable? Why not just use an array?
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
>
为什么你需要一个新的变量名称?为什么不使用数组?
Why do you need a new name for the variable? Why not just use an array?
因为我使用字符串在Macromedia Flash
界面中发送变量。
Because i use the string to send the variable in a Macromedia Flash
interface.
你真的不需要变量的新名称
如果你需要同时保存所有的新闻字符串,你可以使用
数组或ArrayList
ArrayList newsList = new ArrayList();
foreach(table.rows中的行r)
{
int i = r [" ID"];
newsList.Add(" news" + i);
}
newsList将保留所有字符串。你只需要参考,而不是
的名字。
-
使用M2,Opera的革命性e-邮件客户端: http://www.opera.com/m2/
笑一笑,尝试使用Opera的用户模式进行网页浏览,并启用Nostalgia
You don''t really need a new name for the variable
If you need to hold all the news strings at the same time you can use an
array or ArrayList
ArrayList newsList = new ArrayList();
foreach(row r in table.rows)
{
int i = r["ID"];
newsList.Add("news" + i);
}
newsList will then hold all the strings. You only need the reference, not
the name.
--
Using M2, Opera''s revolutionary e-mail client: http://www.opera.com/m2/
For a laugh, try web browsing with Opera''s User Mode with Nostalgia enabled
这篇关于为字符串创建动态名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!