18

What does the 'friend' modifier do in VB.NET?

Why is it the default modifier for GUI components in Visual Studio?

CJ7
  • 22,579
  • 65
  • 193
  • 321

2 Answers2

32

friend in VB.Net is the same as internal in C#, it means that it can be accessed anywhere in the same assembly, but not from other assemblies.

I think it's a sensible default since I would say that normally one assembly should not be using another assembly's GUI controls (unless it's a class library or similar that is built for the purpose).

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
  • 5
    I would go further and say that `Private` would be a better default modifier. Directly accessing another object's GUI controls is poor practise and will lead to tightly-coupled code that's hard to modify. – MarkJ May 06 '10 at 13:23
  • Well, I'm not disagreeing about best practices, but I assume it defaults to friend to make it easier for beginners to get started or something like that. – Hans Olsson May 06 '10 at 14:57
9

Friend is available in VB: The Friend (Visual Basic) keyword in the declaration statement specifies that the elements are accessible from within the same assembly,
From here

I believe the c# version is internal

djv
  • 15,168
  • 7
  • 48
  • 72
DannyLane
  • 2,096
  • 1
  • 16
  • 17