ARTICLE

Friend access modifier in vb.net

Posted by Sapna Articles | Visual Basic Language July 22, 2011
Friend is default access modifier for that class that does not have an access modifier.
Download Files:
 
Reader Level:

Friend is default access modifier for that class that does not have an access modifier. This access modifier is accessible only within the program that contains the entity declaration. External classes from your project cannot access this modifier.

Class1.vb

Public Class Class1
    Friend number As Integer

End
Class

Public Class Class2
    Public Sub CheckMethod()
        Dim x As New Class1()
        x.number = 65
    End Sub

End
Class
 

Class3.vb

Public Class Class3
    Public Sub OtherMethod()
        Dim x As New Class1()
        x.number = 78
        Console.WriteLine()
        Console.WriteLine(x.number)
    End Sub

End
Class

Module1.vb

Module Module1
    Sub Main()
        Dim x As New Class3()
        x.OtherMethod()
        Console.ReadLine()
    End Sub

End
Module

Output

Friend

If you try to assign integer value to x then you will get an error. See below figure2.

Public Class Class3
    Public Sub OtherMethod()
        Dim x As New Class1()
        x = 78
        Console.WriteLine(x.number)
    End Sub

End
Class

Output

Friend

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Become a Sponsor