mx1txm
mx1txm

Reputation: 139

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

when I was using Xamarin.Essentials, I needed to add an assembly reference. What is the difference between them? I though both were references. Thanks!

Upvotes: 0

Views: 51

Answers (1)

Thomas Hilbert
Thomas Hilbert

Reputation: 3629

If an assembly A references an assembly B, then A can use all public types that are contained in B. So it's all about making the contents of another assembly known to your assembly.

The using keyword is used within source files to conveniently allow you to refer to types within a certain namespace without having to specify their full name.

You can access any type without using by specifying their full name like

void MyMethod()
{
    var myList = new System.Collections.Generic.List<int>();
}

But if you put a using statement into your source, you can refer to the type more easily like

using System.Collections.Generic;

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

So using is really only a convenience feature to make your code more easily written and read.

Upvotes: 1

Related Questions