Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The difference between Mono C# Compiler and MS C# Compiler Regarding Scope

I'm running in a corner case here with regarding the difference with scoping of instance methods/properties in C#. Here is the code:

public class Base
{
   public EventHandler Click {get;set;}
   public Base(EventHandler clickHandler)
   {
      this.Click = clickHandler;
   }
}

public class Derived: Base
{
   public Derived(): base((sender, e) => Execute())
   {
   }

   private void Execute()
   {
   }
}

The code compiles fine on MonoDevelop 3.0, but gives an error in VS2010 saying: An object reference is required for the non-static field, method, or property "Base.Execute" Basically, it boils down to the fact that when calling base class's constructor from derived class's constructor, MS's C# compiler does not allow access to derived class's methods/properties, etc. How so?

like image 634
imgen Avatar asked May 14 '12 05:05

imgen


People also ask

What is the difference between mono PERC and mono crystalline?

The standard monocrystalline cell presents a uniform back surface field (BSF), whereas the mono PERC solar cell presents local BSF atop passivation and SINx capping layers, which significantly improves the capture of light and electrons.

Is monocrystalline or amorphous better?

Monocrystalline solar panels are more efficient than amorphous panels. This means they require less space to produce the same amount of electricity. Monocrystalline solar panels also have a longer lifespan and are more resistant to environmental degradation.

How good are crystalline solar panels?

Pros: Monocrystalline solar panels have the highest efficiency rates, typically in the 15-20% range. This high efficiency rate means they produce more power per square foot, and are therefore very space-efficient. Monocrystalline solar panels tend to be more efficient in warm weather.

What's the difference between Poly and mono solar panels?

The main difference between the two technologies is in the crystal purity of the panel cells. Monocrystalline solar panels have solar cells made from a single crystal of silicon while polycrystalline solar panels have solar cells made from several fragments of silicon melted together.


1 Answers

The VS compiler follows the specification. Not sure what is the reason it is allowed in Mono implemetation.

C# Specification, section 10.11.1 Constructor initializers:

An instance constructor initializer cannot access the instance being created. Therefore it is a compile-time error to reference this in an argument expression of the constructor initializer, as is it a compile-time error for an argument expression to reference any instance member through a simple-name.

like image 160
Alexei Levenkov Avatar answered Oct 17 '22 15:10

Alexei Levenkov