❔ 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
you would have to nest the definition of Class2 in Class1, but why do this at all?
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
that sounds like a bigger design problem to me
If you have 50 static classes you have bigger problems yeah
nah I was just using this as an example
im just starting a project I have 1 static class thats all
well, make sure you don't end up with a mess where this question stops being theoretical
I guess if I really needed to organize I could use a namespace as container instaed of an other static class
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
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"
i would probably do something that isn't dump them in separate static classes
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
one static class
StringExtensions
full of extensions methods
how bout that?
put into an Extensions
folder along with other extensions if neededThis is why partial classes are a thing
Your "folder" would then be the file name
good call
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
Again you have much bigger problems if you put 2000 methods in one class
well thats what im saying i want to put them in different classes
XD
anyways its ok
I mean putting them in nested classes doesn't fix the underlying issue
i have my answer i can nest with partial classes or use namespace
is there a specific reason you're refusing to listen to us to improve your underlying design flaws?
is there a design to be flawed to begin with? isn't this whole question theoretical?
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.