Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm trying to convert some code from VB to C#. I made a "friend" function in VB as "internal" in C#. However, friend functions can be called without an object unlike internal functions. So, I made the internal function static so that I could call it using the class name (similar to how the friend function worked). I'm not very happy with this. Is there a better way to do this ? Classes A and B are in the same assembly of course.

What I have tried:

C#
class A{
internal void function(){//do something}
}
class B{
void CallFunction(){A.function(); //not possible !
}
}
Posted
Updated 15-Mar-17 2:35am

Have a look at this chart. It will answer this and many other questions for you... VB.NET and C# Comparison[^] ... it helped me with my transition to C#.
 
Share this answer
 
Comments
Swathi R 15-Mar-17 8:39am    
Thanks for the chart. But I already have done what is mentioned in the chart (conversion of "friend" to "internal"). My question is beyond that.
Graeme_Grant 15-Mar-17 10:22am    
Your question indicates that you are still struggling with it. The chart clears up the confusion conveyed in your question. If you aren't confused, then maybe you need to express that more clearly in the question being asked. Then we can give a more informed response.
VB's Friend is the equivalent of C#'s internal - it does not allow you to access the method without an instance just by using the class name in either language. To do that in VB, you specify Shared - for C# it's static.

I suspect that your VB methods are marked as Friend Shared rather than just Friend - which would allow them instance-free access, just like a C# internal static method.
 
Share this answer
 
Comments
Swathi R 15-Mar-17 8:40am    
No. Its just Friend.

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