估计很多同学都见过typeof这个方法,但是实际中很少使用吧。 typeof方法用于获取类型,返回一个Type对象,根据这个Type对象,我们可以知道这个类型的方法,参数,成员等信息都可以得到,也许是老夫层次太低,不知道这有什么用,要看方法直接F12(vs)就能看到。 

foreach (Control c in Controls)
             {
                 if (c.GetType() == typeof(TextBox))
                 {
                     c.Text = "Hello";
                 }
                 if (c.GetType() == typeof(Button))
                 {
                     ((Button)c).Text = "hello";
                 }
             }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2021-11-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-16
  • 2021-05-27
相关资源
相似解决方案