C
C#11mo ago
PatrickG

❔ can a static class contain static class as property

Let's say I make static Class1 in a file in an other file I make static Class2 Is there a way to make it so I could call Class1.Class2.Method() ??
22 Replies
Jimmacle
Jimmacle11mo ago
you would have to nest the definition of Class2 in Class1, but why do this at all?
PatrickG
PatrickG11mo ago
idk just for readability. lets say i have 50 static classes and I want to regroup them into a few categories to call them more easily in my code
Jimmacle
Jimmacle11mo ago
that sounds like a bigger design problem to me
ero
ero11mo ago
If you have 50 static classes you have bigger problems yeah
PatrickG
PatrickG11mo ago
nah I was just using this as an example im just starting a project I have 1 static class thats all
Jimmacle
Jimmacle11mo ago
well, make sure you don't end up with a mess where this question stops being theoretical LUL
PatrickG
PatrickG11mo ago
I guess if I really needed to organize I could use a namespace as container instaed of an other static class
Jimmacle
Jimmacle11mo ago
i can't really give you specific advice without a real world problem if you wanted to dump a bunch of stuff in a static class, you can make the other utility classes non-static and make them properties of the static class
PatrickG
PatrickG11mo ago
idk man, lets say you had a projet that requires literally TONS of weird specific string manipulations like thousands of them. and you first categorize them into a bunch of static Classes and then you would want to put all these static classes into a StringManipulationStaticClasses "folde"
Jimmacle
Jimmacle11mo ago
i would probably do something that isn't dump them in separate static classes
PatrickG
PatrickG11mo ago
well if you put them all in the same static class it would take 2 hours just to find the proper one you know with the autocomplete
Florian Voß
Florian Voß11mo ago
one static class StringExtensions full of extensions methods how bout that? put into an Extensions folder along with other extensions if needed
ero
ero11mo ago
This is why partial classes are a thing Your "folder" would then be the file name
Florian Voß
Florian Voß11mo ago
good call
PatrickG
PatrickG11mo ago
no lets stay I type StringExensions. ; then i will get a popup with all the existing mothods but there will be 2000 of them the autocomplete will have 2000 suggestions
ero
ero11mo ago
Again you have much bigger problems if you put 2000 methods in one class
PatrickG
PatrickG11mo ago
well thats what im saying i want to put them in different classes XD anyways its ok
ero
ero11mo ago
I mean putting them in nested classes doesn't fix the underlying issue
PatrickG
PatrickG11mo ago
i have my answer i can nest with partial classes or use namespace
ero
ero11mo ago
is there a specific reason you're refusing to listen to us to improve your underlying design flaws?
Jimmacle
Jimmacle11mo ago
is there a design to be flawed to begin with? isn't this whole question theoretical?
Accord
Accord11mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.