Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what is shared function in any given class ?
and what is the use of it ?
with example please
Posted

1 solution

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,

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

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


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


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).
 
Share this answer
 
Comments
Ali Albasri 27-Dec-14 9:00am    
Thank you so much
if i want to create new instance of a class from a function that already a member of this class, would that be OK ??
Am I need the function to be Shared ??
Afzaal Ahmad Zeeshan 27-Dec-14 9:29am    
A static member won't be accessible if you create an instance of the class, it is only accessible without any instance.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900