Resolved Trying to use the "using static directive" in one of my classes but its not working

sock1992

Well-known member
Joined
May 20, 2020
Messages
53
Programming Experience
Beginner
I've currently been using "classname." to access methods in other classes however I read about the using static directive and thought id try it out, howeverim having a bit of an issue.

I've added the name space "using static System."class name" but its not letting me use the methods from that class specified, its just throwing an error. Can anyone help? Thankyou

C#:
using System;
using System.Collections.Generic;
using System.Linq;
using static System.User; // this here is throwing an error and wont allow me to use a static Dictionary
 
Last edited:

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,451
Location
Sydney, Australia
Programming Experience
10+
Is the PatientDictionary property declared static? I doubt it, so that would explain why you can't access it courtesy of using static. Of course, if you'd provided the actual error message then we wouldn't have to guess. Error messages are ALWAYS relevant.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,451
Location
Sydney, Australia
Programming Experience
10+
By the way, I notice that you imported System.Patient. Is that the correct namespace for that class? If it's not then that might also explain your issue. If it is, don't be declaring your own namespace named System, because then you confuse system code with your own code and increase the likelihood of name clashes.
 
Last edited:

sock1992

Well-known member
Joined
May 20, 2020
Messages
53
Programming Experience
Beginner
By the way, I notice that you imported System.Patient. Is that the correct namespace for that class? If it's not then that might also explain your issue, if it is, don't be declaring your own namespace named System, because then you confuse system code with your own code and increase the likelihood of name clashes.
Sweet, I fixed it. I wasn't typing the name of my project :rolleyes::D
 
Top Bottom