如何判断给定的类属于哪个命名空间? [英] How can I tell which namespace agiven class belongs to?

查看:61
本文介绍了如何判断给定的类属于哪个命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常会在网上找到我想使用的代码片段,但该片段没有提供我需要的必要导入(C# 中的使用"),所以我只剩下另一个试图找出类/变量类型属于哪个命名空间的搜索任务.这个问题只发生在我在 Visual Studio C# 中用 Xamarin 编程 Android 时,因为我看不到 android 文档在哪里显示了这个信息.(如果我用普通的 C# 编程,那么 MSDN 文档非常清楚每个类属于哪个命名空间.)

It happens a lot that I might find a snippet of code on the web that I want to use, but the snippet doesn't provide the necessary imports I need ("Using" in C#), so I am left with another search task of trying to figure out what namespace a class/variable type belongs to. This problem is only happeneing to me when I program Android with Xamarin in Visual Studio C#, because I cannot see where the android documentation shows me this info. (If I am programming in normal C# then the MSDN Documentation is very clear what namespace each class belongs to.)

这是一个例子.我找到了我想使用的以下代码:

Here is an example. I found the following code I want to use:

Configuration configuration = yourActivity.getResources().getConfiguration();
int screenWidthDp = configuration.screenWidthDp; //The current width of the available screen space, in dp units, corresponding to screen width resource qualifier.
int smallestScreenWidthDp = configuration.smallestScreenWidthDp; //The smallest screen size an application will see in normal operation, corresponding to smallest screen width resource qualifier.

回答者甚至给出了 Android 文档的链接:
http://developer.android.com/reference/android/content/res/Configuration.html#screenWidthDp

And the answerer even gave a link to the Android Documentation:
http://developer.android.com/reference/android/content/res/Configuration.html#screenWidthDp

但是在 VS 中,我收到一条错误消息:找不到类型或命名空间名称‘配置’(您是否缺少 using 指令或程序集引用?)

However within VS I get an error message: "The type or namespace name 'Configuration' could not be found (are you missing a using directive or an assembly reference?)

嗯,是的,我缺少 using 指令,但是有什么方法可以找出我缺少的命名空间的名称?同样,如果它是一个普通的 .Net 类,我没有问题,这只会发生在 Xamarin/VS 中的 Android 类中,因为我没有在 Android 文档中找到我需要的东西.请问有人能指点一下吗?

Well, yes I am missing a using directive, but what is a way of figuring out the name of the namespace I am missing? Again if it is a normal .Net class I have no trouble, this only happens to me with Android classes within Xamarin/VS, because I am not finding what I need in the Android documentation. Could someone point me to it, please?

推荐答案

通常,我在一个类上按 F1 来查找它的在线文档.在 Android 课堂上试一试

Normally, I press F1 on a class to find the online document of it. Try it out on the Android class

您还可以在 Xamarin 中找到所需的文档微软的页面.您还可以在此页面搜索您将来可能需要的任何其他课程.

You can also find your desired documentation in the Xamarin page of Microsoft. You can also search this page for any other class that you might need in the future.

这篇关于如何判断给定的类属于哪个命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆