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.Re…
public partial class Form1 : Form { string str = "spp"; public string spp = "very good"; public Form1() { InitializeComponent(); MessageBox.Show(this.GetType().GetField(str).GetValue(this).ToString()); } }…
可以实现的方法有: globals(),locals(),eval(),exec() 演示: exce法 In [6]: exec('name="bob"') In [7]: name Out[7]: 'bob' globals用法: In [1]: globals()['name']='bob' In [2]: name Out[2]: 'bob'…
今天骚凯问了一道变量名冲突的题目,感觉很有意思,顺便也复习一下预解析的一些知识,有不对的地方忘前辈大神指正,题目是这样的: var a=100; function a(){ console.log(a); } a(); 这个串代码执行完会报错 : a is not a function 问题来了,为什么会报这个错误呢? 这里涉及到函数和变量的预解析: 1)函数声明会置顶2)变量声明也会置顶3)函数声明比变量声明更置顶:(函数在变量上面)4)变量和赋值语句一起书写,在js引擎解析时,会将其拆成声…
JavaScript中不能作为变量名的关键字和保留字总结: 1.js中的关键字: break case catch continue default delete do else finally for function if in instanceof new return switch this throw try typeof var void while with 2.js中的保留字: abstract boolean byte char class const debugger dou…
1 把字符串当变量使用 通过计算 string 得到的值(如果有的话).该方法只接受原始字符串作为参数 demo: var type = "car"; var newStr = "type"; var x = 100; eval("2+2"); eval("type"); eval("x + 17"); console.log(eval("2+2"), eval("type&q…