944,065 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 510
  • C# RSS
Nov 1st, 2009
0

[ASK] C# Namespace Problem

Expand Post »
Hi, I've code like this

C# Syntax (Toggle Plain Text)
  1. namespace RestaurantSoftClassLib.Karyawan
  2. {
  3. public class Karyawan
  4. {
  5. blablabla
  6. }
  7. }

when I want to use the Karyawan's Class in User's Class
C# Syntax (Toggle Plain Text)
  1. using RestaurantSoftClassLib.Karyawan;
  2.  
  3. namespace RestaurantSoftClassLib.User
  4. {
  5. public class User
  6. {
  7. Karyawan.Karyawan karyawan;
  8. blablabla
  9. }
  10. }

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

Thanks.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
skylancer is offline Offline
7 posts
since Nov 2009
Nov 1st, 2009
0
Re: [ASK] C# Namespace Problem
Hello.
That's weird .. works fine for me when I use this:
c# Syntax (Toggle Plain Text)
  1. using RestaurantSoftClassLib.Karyawan;
and then
c# Syntax (Toggle Plain Text)
  1. Karyawan karyawan;

Try to remove one Karyawan .. what's happening if you use only one?
Last edited by Antenka; Nov 1st, 2009 at 4:47 pm.
Reputation Points: 293
Solved Threads: 82
Posting Whiz
Antenka is offline Offline
361 posts
since Nov 2008
Nov 2nd, 2009
0
Re: [ASK] C# Namespace Problem
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"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
skylancer is offline Offline
7 posts
since Nov 2009
Nov 2nd, 2009
0
Re: [ASK] C# Namespace Problem
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
Reputation Points: 2035
Solved Threads: 645
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Nov 2nd, 2009
0
Re: [ASK] C# Namespace Problem
so...what is the solution? so that I can use only Karyawan
Reputation Points: 10
Solved Threads: 0
Newbie Poster
skylancer is offline Offline
7 posts
since Nov 2009
Nov 2nd, 2009
1
Re: [ASK] C# Namespace Problem
Put your Karyawan class in the RestaurantSoftClassLib namespace not in the RestaurantSoftClassLib.Karyawan namespace.
Reputation Points: 2035
Solved Threads: 645
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Nov 2nd, 2009
0
Re: [ASK] C# Namespace Problem
Yes, its works. Thanks ddanbe.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
skylancer is offline Offline
7 posts
since Nov 2009
Nov 2nd, 2009
0
Re: [ASK] C# Namespace Problem
Hello.
Or use using directive inside of target namespace:
c# Syntax (Toggle Plain Text)
  1. namespace RestaurantSoftClassLib.User
  2. {
  3. using RestaurantSoftClassLib.Karyawan;
  4. class User
  5. {
  6. Karyawan karyawan;
  7. }
  8. }

In your code the RestaurantSoftClassLib is visible even without this:
c# Syntax (Toggle Plain Text)
  1. 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
Last edited by Antenka; Nov 2nd, 2009 at 6:45 am. Reason: Forgot ...
Reputation Points: 293
Solved Threads: 82
Posting Whiz
Antenka is offline Offline
361 posts
since Nov 2008
Nov 2nd, 2009
0
Re: [ASK] C# Namespace Problem
Did you also check your references?
Reputation Points: 2035
Solved Threads: 645
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Programming Live Chat
Next Thread in C# Forum Timeline: hi..





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC