在c#中把字符串轉(zhuǎn)為變量名并獲取變量值的小例子
更新時間:2013年09月02日 15:38:54 作者:
這篇文章介紹了在c#中把字符串轉(zhuǎn)為變量名并獲取變量值的小例子,有需要的朋友可以參考一下
復(fù)制代碼 代碼如下:
public class Program
{
public string str = "spp";
public string spp = "Hello World!";
public static void Main(string[] args)
{
Program p = new Program();
Console.WriteLine(p.GetType().GetField(p.str).GetValue(p).ToString());
Console.ReadKey();
}
}
相關(guān)文章
C#強(qiáng)制轉(zhuǎn)換和嘗試轉(zhuǎn)換的方法
這篇文章主要為大家詳細(xì)介紹了C#強(qiáng)制轉(zhuǎn)換和嘗試轉(zhuǎn)換的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-09-09c#連接sqlserver數(shù)據(jù)庫、插入數(shù)據(jù)、從數(shù)據(jù)庫獲取時間示例
這篇文章主要介紹了c#連接sqlserver數(shù)據(jù)庫、插入數(shù)據(jù)、從數(shù)據(jù)庫獲取時間示例,需要的朋友可以參考下2014-05-05