Using a self reference in a field declaration (+1 VB.Net)

When declaring a field, C# does not allow you to use the “this” keyword, whereas does VB.Net allow you (though it is called “Me”).


Private _ClassNeedsRef As New ClassNeedsRef (Me)


private ClassNeedsRef _ClassNeedsRef ;

public ClassWithRef() {
    _ClassNeedsRef = new ClassNeedsRef(this);

When trying to think of a reason for this, a friend of mine, Robert, suggests that C# may do this for clarity reasons, though this is only a guess.

At first we though that C# may not want to pass an unconstructed reference, but this cannot be the case, since it does allow you to pass the reference in the constructor.


1 comment so far

  1. Ecko on

    nice share, thanks

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: