[ASK] C# Namespace Problem

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2009
Posts: 4
Reputation: skylancer is an unknown quantity at this point 
Solved Threads: 0
skylancer skylancer is offline Offline
Newbie Poster

[ASK] C# Namespace Problem

 
0
  #1
24 Days Ago
Hi, I've code like this

  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
  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 249
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training
 
0
  #2
24 Days Ago
Hello.
That's weird .. works fine for me when I use this:
  1. using RestaurantSoftClassLib.Karyawan;
and then
  1. Karyawan karyawan;

Try to remove one Karyawan .. what's happening if you use only one?
Last edited by Antenka; 24 Days Ago at 4:47 pm.
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 4
Reputation: skylancer is an unknown quantity at this point 
Solved Threads: 0
skylancer skylancer is offline Offline
Newbie Poster
 
0
  #3
24 Days Ago
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"
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,909
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 274
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso
 
0
  #4
23 Days Ago
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
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 4
Reputation: skylancer is an unknown quantity at this point 
Solved Threads: 0
skylancer skylancer is offline Offline
Newbie Poster
 
0
  #5
23 Days Ago
so...what is the solution? so that I can use only Karyawan
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,909
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 274
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso
 
1
  #6
23 Days Ago
Put your Karyawan class in the RestaurantSoftClassLib namespace not in the RestaurantSoftClassLib.Karyawan namespace.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 4
Reputation: skylancer is an unknown quantity at this point 
Solved Threads: 0
skylancer skylancer is offline Offline
Newbie Poster
 
0
  #7
23 Days Ago
Yes, its works. Thanks ddanbe.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 249
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training
 
0
  #8
23 Days Ago
Hello.
Or use using directive inside of target namespace:
  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:
  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; 23 Days Ago at 6:45 am. Reason: Forgot ...
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,909
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 274
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso
 
0
  #9
23 Days Ago
Did you also check your references?
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC