- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在什么情况下会在 VB.NET 中使用 MyBase
和 MyClass
关键字?
最佳答案
当虚拟函数需要调用其父版本时,使用
MyBase
。例如,考虑:
Class Button
Public Overridable Sub Paint()
' Paint button here. '
End Sub
End Class
Class ButtonWithFancyBanner
Inherits Button
Public Overrides Sub Paint()
' First, paint the button. '
MyBase.Paint()
' Now, paint the banner. … '
End Sub
End Class
(这与 C# 中的 base
相同。)
MyClass
很少使用。它调用自己的类的方法,即使它通常会调用派生类的虚拟方法。换句话说,它取消了虚拟方法分派(dispatch),而是进行静态调用。
这是一个人为的例子。我现在很难找到现实世界的用法(尽管确实存在):
Class Base
Public Overridable Sub PrintName()
Console.WriteLine("I’m Base")
End Sub
Public Sub ReallyPrintMyName()
MyClass.PrintName()
End Sub
End Class
Class Derived
Inherits Base
Public Overrides Sub PrintName()
Console.WriteLine("I’m Derived")
End Sub
End Class
' … Usage: '
Dim b As Base = New Derived()
b.PrintName() ' Prints "I’m Derived" '
b.ReallyPrintMyName() ' Prints "I’m Base" '
(这在 C# 中不存在。在 IL 中,这会发出 call
而不是通常的 callvirt
操作码。)
关于vb.net - "MyBase"和 "MyClass"在 VB.NET 中的用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2849329/
在学习 C++ 的过程中,我偶然发现了文章 Writing Copy Constructors and Assignment Operators它提出了一种机制来避免复制构造函数和赋值运算符之间的代码
显然,以这种方式实现基于类的实例方法是 JavaScript 中的一个习惯用法: function MyClass(){...} MyClass.prototype.methodA = functio
我尝试使用泛型为 NSManagedObject 的子类提供通用方法,但当 Swift 似乎无法找到/将泛型转换为具体类时,我收到错误: /// NSManagedObject+Helper.swif
有什么区别 MyClass mc = MyClass(); 和 MyClass mc; 在 C++ 中? 最佳答案 第一个调用复制构造函数,以临时对象作为参数 - MyClass() 创建临时对象。
考虑不涉及复制省略的情况(C++17 之前)。 来自 cppreference(再次假设 C++14): Temporary objects are created in the following
这里有一些代码: class MyClass { public: int y; }; int main() { MyClass item1; MyClass item2 = M
这种类型转换表达式之间有什么区别?什么是更好的? // One way var t:MyClass = MyClass(o); // Another var t:MyClass = o as MyCl
为了跟踪实例,我们有一个数组 MyClass[] mc = new MyClass[5]; 我想在构造函数调用本身期间保存在此数组中创建的 MyClass 实例。 类似这样的事情: public cl
我在对一个非常简单的类进行子类化时遇到问题,该类也有返回初始类的方法。 public class MyClass { public MyClass(){ } public MyC
我有一个 std::list在我的课上我有 myclass::operator bool PComp(const T * const & a, const T * const & b) { re
我正在编写一个简单的程序来计算面积,我得到的错误是: no matching function for call to 'myclass::myclass()' 我无法理解此错误的原因以及解决方法。
我希望我可以针对这个问题逐字发布我的项目,但我不能。 基本上,我有以下类(class): class Lowest { someValue: string constructo
为什么可以施放MyClass反对 List没有编译错误(只是有“未检查”警告),尽管 MyClass未实现 List 接口(interface),同时无法进行强制转换,例如 String类同样的方式。
我正在这里试验一下。 假设我有一个类: static class MyClass { static String property = "myProperty"; } 和一个方法: publi
我正在尝试为单元测试目的创建一个 stub 类。 Stub 指向完全相同的 EmployeeData 类定义,但编译器认为它们是不同的,不知何故。结果,我不断收到以下消息: Cannot implic
为什么我不能通过 Point src[1][4] = { { Point(border,border), Point(border,h-border),
我有一个正在创建的模板类,我需要一个方法来返回该类的对象并对其进行分配。我有一个方法接收 2 个对象、创建一个新对象并返回它,以及重载赋值运算符以正确复制成员。 我试过用两种方法来做到这一点(两种方法
在 C# 中是否可以在运行时创建一个类型,该类型继承自泛型类,其中基类的模板参数是正在构造的当前类?这将编译正常: // I have this class: public class OtherCl
我有几个带有“listingThumb”类的 div CSS: .listingThumb{ height:50px; width:50px; overflow:hidden; } HTML: 我希
例如,我有一个包含不同容器的类来保存由 new 运算符创建的 MyClass 对象: class A{ MyClass* m; vector vm; vector > vvm;
我是一名优秀的程序员,十分优秀!