V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
d3js
V2EX  ›  C#

C# 中 this 关键字在 Forms 类中使用的困惑

  •  
  •   d3js · 249 天前 · 799 次点击
    这是一个创建于 249 天前的主题,其中的信息可能已经有所发展或是发生改变。

    官方对 this 的定义是:

    this 关键字指代类的当前实例,还可用作扩展方法的第一个参数的修饰符。


    问题:

    1 、在 Forms 类中,使用 this 的话,窗体可以弹出

    2 、在 Forms 类中,不使用 this ,自己去创建实例的话,窗体无法弹出

    这是为啥呢?

    https://i.imgur.com/9OtxuB3.png

    https://i.imgur.com/84UT9Pb.png

    chaselen
        1
    chaselen  
       249 天前   ❤️ 1
    你那个`new MyForm()`都死循环了吧,不停地调构造函数。。。
    d3js
        2
    d3js  
    OP
       249 天前
    @chaselen 大佬,那这个 C# 例子中,要想指代 MyForm 类的当前实例,是不是只能用 this ?
    yuhuai
        3
    yuhuai  
       249 天前   ❤️ 1
    @d3js 你 new 了一个新对象哦,this 代表此窗体 MyForm 这个对象,而你 new 出来的是另外一个
    oott123
        4
    oott123  
       249 天前   ❤️ 1
    用 this:
    this.button.Click

    不用 this:
    button.Click
    forgottencoast
        5
    forgottencoast  
       245 天前
    图片都没了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2958 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 08:46 · PVG 16:46 · LAX 01:46 · JFK 04:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.