简体   繁体   中英

using method in namespace that have same name with I'm working now on

It is strange....

there is a namespace named Android.Graphics and I'm work in the namespace named Xamarin.FormsBook.Platform.Android .

There is one more namespace named Xamarin.Forms and it has Color field.

Now, I want to use Android.Graphics.Color so I write Color then something recognize it as Xamarin.Forms.Color not Android.Graphics.Color .

在此处输入图片说明

And, If I write Android.Graphics.Color the builder could not find Android.Graphics. If I write Android. then builder find Xamarin.FormsBook.Platform.Android 's methods and fields.

在此处输入图片说明

If I write Android.Graphics.Color outside of namespace region, then it recognize.

在此处输入图片说明

But I can't assign any value in it since 'A namespace can not directly contain members such as fields or methods'.

help me, I want to use Color of Android.Graphic

You can do this by using an alias directive :

using AndroidGraphics = Android.Graphics;

You can then refer to the Android.Graphics.Color type by using the alias name AndroidGraphics.Color . Since there isn't another namespace called AndroidGraphics your compiler will resolve it correctly.

Alias directives can also be used for individual types, so you could also do the following:

using AndroidColor = Android.Graphics.Color;

and then refer to the type using AndroidColor .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM