在课堂上共享功能 [英] shared function in class

查看:59
本文介绍了在课堂上共享功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何给定类中的共享函数是什么?

它的用途是什么?

请举例

what is shared function in any given class ?
and what is the use of it ?
with example please

推荐答案

VB.NET中的共享关键字在C#中也称为 static 。这意味着这些对象(使用此关键字声明)可由其他函数和类访问,而无需创建新实例。例如,



The Shared keyword in the VB.NET is also known as static in C#. It means that these objects (that are declared with this keyword) are accessible by other functions and classes without having to create a new instance. For example,

public class Example {
   public static string Member = "";
}

// in the code somewhere, you can directly get the value as
Example.Member;







Public Class Example
	Public Shared Member As String = ""
End Class





以下是VB.NET代码。你可以看到静态是静态的等价物。这样就可以通过其他方法访问成员(在这种情况下是成员),即使在对象被清除之后(销毁;静态成员保留在内存中直到程序继续运行)。



The following is the VB.NET code. You can see, that the static is the equivalent for the static. This would let the member (Member in this case) to be accessible by other methods, even after the object has been cleared out (destroyed; static members remain in the memory until the program keeps running).


这篇关于在课堂上共享功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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