名称存储在另一个变量中的变量的访问值 [英] Access value of variable whose name is stored in another variable

查看:36
本文介绍了名称存储在另一个变量中的变量的访问值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 C#,我可以访问名称存储在另一个字符串变量中的变量的内容吗

Using C#, could I able to access a content of a variable whose name is stored in another string variable

例如

string str ="ABCDEFG";
string variable = "str";

这里我可以使用 var 访问字符串 str 的值吗????

Here could i access value of string str using var????

推荐答案

你可能可以,但这太复杂了.你有没有想过使用 Dictionary 类?

you probably can, but that's too complicated. Have you thought of using the Dictionary class?

Dictionary<string,string> myDictionary = new Dictionary<string,string>();

myDictionary["str"] = "ABCDEF";

var valueinstr = myDictionary["str"];

这篇关于名称存储在另一个变量中的变量的访问值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆