Hi, I've code like this

namespace RestaurantSoftClassLib.Karyawan
{
   public class Karyawan
   {
       blablabla
   }
}

when I want to use the Karyawan's Class in User's Class

using RestaurantSoftClassLib.Karyawan;

namespace RestaurantSoftClassLib.User
{
    public class User
    {
        Karyawan.Karyawan karyawan;
        blablabla
    }
}

why I used to write Karyawan two times, Karyawan.Karyawan not just Karyawan?

Thanks.

Hello.
That's weird .. works fine for me when I use this:

using RestaurantSoftClassLib.Karyawan;

and then

Karyawan karyawan;

Try to remove one Karyawan .. what's happening if you use only one?

Edited 7 Years Ago by Antenka: n/a

Try to remove one Karyawan .. what's happening if you use only one?

if I remove one there is an error like this
"Error 1 'RestaurantSoftClassLib.Karyawan' is a 'namespace' but is used like a 'type' C:\Documents and Settings\sky\My Documents\Visual Studio 2008\Projects\RestoranSoft\RestaurantSoftClassLib\User\User.cs 18 9 RestaurantSoftClassLib"

The confusion comes from the fact that Karyawan is a namespace which contains a class with the name Karyawan.
If you have a namespace A with classes A and B, you would also say A.A and A.B

Put your Karyawan class in the RestaurantSoftClassLib namespace not in the RestaurantSoftClassLib.Karyawan namespace.

Comments
solver++

Hello.
Or use using directive inside of target namespace:

namespace RestaurantSoftClassLib.User
{
    using RestaurantSoftClassLib.Karyawan;
    class User
    {
        Karyawan karyawan;        
    }
}

In your code the RestaurantSoftClassLib is visible even without this:

using RestaurantSoftClassLib.Karyawan;

Because the User namespace is inside RestaurantSoftClassLib . And if you remove this using - there will be no effect. I'm not sure, but suppose that this relationships are more significant and the code, when you're trying to make a reference on RestaurantSoftClassLib.Karyawan is just being ignored.
But since the User is aware of RestaurantSoftClassLib - it has no idea about Karyawan.
So if you restrict the scope of using directive to particular namespace - it would work just fine :)

Edited 7 Years Ago by Antenka: Forgot ...

This article has been dead for over six months. Start a new discussion instead.