Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2005

Tip: Looking for answers? Try searching our database.

Question on access modifier of interface members in VB.NET And C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
prakash - 27 Jul 2005 14:56 GMT
Dear Friends

The following Code Works Well....
------------------------------------------------------------
Public Interface IHello
    Sub SayHello()
End Interface

Public Class Hello
    Implements IHello

    Private Sub SayHello() Implements IHello.SayHello
        MessageBox.Show("Say Hello On the Hello Class")
    End Sub
End Class

    Dim HelloObject As New Hello
    'HelloObject.SayHello()  -> Not Accessible

    Dim IHelloObject As IHello
    IHelloObject = CType(HelloObject, IHello)
    IHelloObject.SayHello()
-------------------------------------------------------
This code would not compile...

    public interface IHello
    {
        void SayHello();
    }

    public class Hello : IHello
    {
        private void SayHello()
        {
            MessageBox.Show("Say Hello On the Hello Class");
        }
    }

-----------------------------------------------------------
VB.NET allows the modifers friend,public,private for interface
implementars
C# allows only public...

Why this inconsistency ??

Regards
Prakash
Mattias Sjögren - 27 Jul 2005 16:26 GMT
>-----------------------------------------------------------
>VB.NET allows the modifers friend,public,private for interface
>implementars
>C# allows only public...
>
>Why this inconsistency ??

Different languages have different features and syntax.

To achieve private (explicit) implementation in C# you write

void IHello.SayHello()
{
}

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

prakash - 28 Jul 2005 05:39 GMT
Hi Mattias

That works !!!!!!!!!!!!!!!!!!!

what is term (explicit ) implementation meant by??

What is the difference b/w this two ??

public void SayHello()

void IHello.SayHello()

regards
prakash
Jon Skeet [C# MVP] - 28 Jul 2005 07:05 GMT
> That works !!!!!!!!!!!!!!!!!!!
>
[quoted text clipped - 5 lines]
>
> void IHello.SayHello()

Look up "explicit interface implementation" in the MSDN index, and
you'll find "Explicit Interface Implementation Tutorial" - that takes
you through it, and has links to the relevant sections of the C# spec.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

prakash - 28 Jul 2005 08:53 GMT
Thanks Jon Skeet...

I learn the explict and implicit interface declarations. They are
interesting topics...

I think default implementation of VB.NET is explicit interface
implementation.

How can we implement an interface member using  "implicit interface
implementation" in VB.NET??

Ragards
prakash
Jon Skeet [C# MVP] - 28 Jul 2005 19:34 GMT
> I think default implementation of VB.NET is explicit interface
> implementation.

Not really - it depends on what access modifier you provide.

> How can we implement an interface member using  "implicit interface
> implementation" in VB.NET??

Look at this:

Imports System

Public Class ShortTest
Implements IDisposable

 Public Overridable Sub Dispose Implements IDisposable.Dispose
   Console.WriteLine ("Hello")
 End Sub

 Shared Sub Main
   Dim x as New ShortTest()
   x.Dispose()
 End Sub

End Class

As far as I can tell, that's equivalent to:

using System;

public class ShortTest : IDisposable
{
   public void Dispose()
   {
       Console.WriteLine ("Hello");
   }

   static void Main()
   {
       new ShortTest().Dispose();
   }
}

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

prakash - 29 Jul 2005 07:37 GMT
Thank u very much Jon Skeet

Two interfaces with same member I am used the following syntax.
-------------------------------------------------------------------------------------
Public Interface IHello
    Sub SayHello()
End Interface

Public Interface IHello1
    Sub SayHello()
End Interface

Public Class Hello
    Implements IHello, IHello1

    Public Sub SayHello() Implements IHello.SayHello, IHello1.SayHello
        MessageBox.Show("Say Hello On the Hello Class")
    End Sub
End Class
-------------------------------------------------------------------------------------
regards
prakash

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.