Why am I getting this compilation error in my abstract base class?

I am trying to extend this plugin for my own use ...

https://github.com/jamesmontemagno/Xamarin.Plugins/blob/master/Connectivity/Connectivity/Connectivity.Plugin.Abstractions/BaseConnectivity.cs

But when I copy the code in Visual Studio, I get some error.

enter image description here

Do I need to import some special structure to use the '=>' operator and the 'Invoke' method? This is an abstract base class. I am using VS2013

+5
source share
3 answers

? is a C # 6 function, as well as the => operator (when used for elements with a body expression) is only available in Visual Studio 2015.

Read about them here null-conditional operators and here => operator

C # 6:

protected virtual void OnConnectivityChanged(ConnectivityChangedEventArgs e) { if (ConnectivityChanged != null) ConnectivityChanged.Invoke(this, e); } 
+14
source

?. is Null-conditional operators in C # 6. Do you use C # 6? C # 6 introduced

Replace this code with

 if(ConnectivityChanged != null) { ConnectivityChanged.Invoke(this, e); } 

Is this equivalent to our ConnectivityChanged?.Invoke(this, e); code ConnectivityChanged?.Invoke(this, e);

+4
source

That should do it.

 protected virtual void OnConnectivityChanged(ConnectivityChangedEventArg e) { if(ConnectivityChanged != null) { ConnectivityChanged.Invoke(this,e); } } 
+2
source

Source: https://habr.com/ru/post/1237680/


All Articles