以下显示表格的方法有什么区别? [英] What is the difference between the following methods of Showing forms?

查看:15
本文介绍了以下显示表格的方法有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下两个语句有什么区别(在内存管理方面):

What is the difference between the following two statements (in terms of memory management):

Dim frm as New MyForm()
frm.Show()

VS

MyForm.Show()

我最初是一名 C# 开发人员,第二个如何在 VB.NET 中有意义甚至编译?(Show() 不是共享/静态方法)第二种情况发生了什么?

I am originally a C# developer, how does the second one make sense or even compile for that matter in VB.NET? (Show() is not a Shared/Static method) What is happening in the second case?

推荐答案

MyForm.Show() 出于兼容性原因从 VB6 和之前的版本保留下来.在这些版本中,通常不会创建表单的多个实例,因此当使用 MyForm.Show() 时,它会自动创建表单的单例实例以供默认使用.您不应该使用该方法,而创建实例并在其上调用 .Show() 方法的首选方法是正确的方法,并且与 c# 和其他 .net 语言兼容.

MyForm.Show() is a hold over from VB6 and prior versions for compatibility reasons. In those versions, there typically was no creating multiple instances of a form so when MyForm.Show() was used, it automatically created a singleton instance of the form for default usage. You shouldn't use that method and the preferred method of creating an instance and calling the .Show() method on it is the right way and compatible with c# and other .net languages.

这篇关于以下显示表格的方法有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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