Does Xamarin have #if or #ifdef to define the platform?

For example, #ifdef iOS, #ifdef android, etc. If there is #if, it will be even better.

+7
cross-platform xamarin
source share
2 answers

IOS:

#if __MOBILE__ Console.WriteLine ("__MOBILE__ is defined"); #endif #if __IOS__ Console.WriteLine ("__IOS__ is defined"); #endif 

Android:

 #if __MOBILE__ Console.WriteLine ("__MOBILE__ is defined"); #endif #if __ANDROID__ Console.WriteLine ("__ANDROID__ is defined"); #endif 

https://bugzilla.xamarin.com/show_bug.cgi?id=6459#c12

+10
source share

Yes, yes, I do not know if Xamarin.iOS provides its own characters, since I am new to Xamarin and I actually do not use Xamarin.iOS, but you can define your own characters.

Right-click on the project and open the project settings. In the "Compiler" settings, you can search for existing flags and create new ones. For example, here are the characters that come with Xamarin.Android:

 DEBUG;__MOBILE__;__ANDROID__; 

Flags should be available immediately after they are defined.

+1
source share

All Articles