Brand new Pop Quiz! (Do you like tackling stupid little challenges as much as I do?)

There is absolutely no point (that I can think of, anyway) to doing this, buuut

We all know about ReferenceEquals, right? Look at two variables, see if they reference the same object instance?

Dim x As New Object
Dim y As Object = x
Console.WriteLine(ReferenceEquals(x, y))

The above code will output True. Well, can you think of a way to write a VariableEquals method that will only return True if the same variable is passed in for both parameters?

In other words, given the hypothetical VariableEquals method I just described:

Dim x As Integer = 5
Dim y As Integer = x
Console.WriteLine(VariableEquals(x, y))
Console.WriteLine(VariableEquals(x, x))

…the above code should output False, then True.

Yes, it is possible! (Hints below—highlight the text if you want to see them.)

Hint 1: There’s a reason I wrote the above code in VB.NET. I am intentionally hiding something from you (to make the challenge tougher).
Hint 2: I am not guaranteeing the solution can actually be written in VB.NET, mind you.

Again, there is no point to this. I’m just a tinkerer, so I personally love this sort of stuff.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: