This is probably going to be a very stupid question as I've been away from coding for quite a while and am sure I'm missing something basic, but.. When working on a new project in Visual Studio I, as usual, started grouping some of my .cs files into folders to make the solution explorer more maneuverable. For one folder, I can access it in code like normal - foldername.filename.method. Every other folder, however, does not show up in the auto-correct when I type it's name, and it says that they don't exist in the current context. Does anyone have any clue what I'm missing or that could be wrong?
6 replies to this topic
#1
Posted 15 September 2011 - 08:58 PM
|
|
|
#2
Posted 17 September 2011 - 02:54 AM
As far as I know in C# putting source files in directories doesn't make a difference for their "visibility" in code, it's just for your convinience. But what does make a difference - is namespaces :)
#3
Posted 17 September 2011 - 11:28 AM
That was one of the first things I thought of, but I checked and all the namespaces match.
#4
Posted 17 September 2011 - 05:27 PM
sonar87 said:
For one folder, I can access it in code like normal - foldername.filename.method.
#5
Posted 18 September 2011 - 01:06 PM
Well how it always worked before was calling the name of the folder I had everything in, then .classname.method Only now its acting like the folders aren't there.
#6
Posted 18 September 2011 - 02:48 PM
That's because the folders were part of the namespace the files were in. Now you say they aren't, so you don't need it.
If you create a project and call it 'Fred' it will have a namespace of 'Fred'. If you now create a folder in this project called 'MyFolder' and then create a file under that folder (all in the IDE, of course), it will have a namespace of 'Fred.MyFolder'. In the original file you'll have a 'using Fred' line, and you can use stuff from MyFolder by writing 'MyFolder.ClassName' or by adding a 'using Fred.MyFolder' and then you can just use the ClassName.
If you create a project and call it 'Fred' it will have a namespace of 'Fred'. If you now create a folder in this project called 'MyFolder' and then create a file under that folder (all in the IDE, of course), it will have a namespace of 'Fred.MyFolder'. In the original file you'll have a 'using Fred' line, and you can use stuff from MyFolder by writing 'MyFolder.ClassName' or by adding a 'using Fred.MyFolder' and then you can just use the ClassName.
#7
Posted 21 September 2011 - 09:46 PM
Momerath said:
and you can use stuff from MyFolder by writing 'MyFolder.ClassName'
And, under the circumstances you've just stated this ^ is exactly what I'm trying to do, and it is not working.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









