"using" 和 "assembly" 有什么区别?

What is the differnce between "using" and an "assembly"?

当我使用 Xamarin.Essentials 时,我需要添加一个程序集引用。它们之间有什么区别?我虽然两者都是参考。谢谢!

如果程序集 A 引用程序集 B,则 A 可以使用 B 中包含的所有 public 类型。所以这就是让您的程序集知道另一个程序集的内容。

using 关键字用于源文件中,方便您引用特定命名空间中的类型,而无需指定其全名。

您可以通过指定全名如

来访问任何没有using的类型
void MyMethod()
{
    var myList = new System.Collections.Generic.List<int>();
}

但是如果你把一个 using 语句放到你的源代码中,你可以像

这样更容易地引用类型
using System.Collections.Generic;

void MyMethod()
{
    var myList = new List<int>();
}

所以 using 实际上只是一个方便的功能,可以让您的代码更容易编写和阅读。