Question

I'm new to programming.

I want to know in VB.NET what is difference between these two:

System.Drawing.Image.FromFile()

and

Image.FromFile()

I used both on a picturebox, and both worked. I just want to know what is difference and which is standard.

Was it helpful?

Solution

If you start a new WinForms VB.NET project using Visual Studio, you will find that the namespace System.Drawing is automatically added to the project references and an Import System.Drawing is already in place.

Try to right click on your project, listed in the Solution Explorer window, then select Properties and then click on the References tab.
You will see two lists. The first one contains the references to the assemblies automatically added to your project, the second list contains the Import statements implicitily written for you by the VS IDE

This means that you can call any method from the classes included in the System.Drawing namespace without fully qualifying them. This is also true for the other imported namespaces like System (For example, you don't need to write System.Convert.ToInt32 but just Convert.ToInt32).

In this context doesn't matter if you type the fully qualified method name or just the abbreviated version. You can always write the fully qualified name.

Of course the shortcut provided importing the reference is very handy and will save a lot of time during coding.

OTHER TIPS

The first one is just the fully qualified namespace. If you have imported the System.Drawing namespace you can access the Image.FromFile() without calling the whole namespace.

There is no difference. You're calling one with the full name space System.Drawing.Image.FromFile(string) and the other Image.FromFile(string) without it. The second call assumes that you've included using System.Drawing in your class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top