Re: Making static class ToString() not possible, why?
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Thu, 19 Apr 2007 17:22:13 -0700
On Thu, 19 Apr 2007 17:07:25 -0700, Zytan <zytanlithium@xxxxxxxxx> wrote:
[...]
I hope I can possibly explain why I wanted to do such a crazy thing,
it's because there was only one instance of this struct. And it had a
ToString() to easily print out all of its data. So, I made a static
class out of it, instead, which forces only one 'copy' of it.
Well, the usual solution to doing something like that is what seems to be called around here "the Singleton pattern" (sorry...I'm still getting used to seeing the word "pattern" applied to coding practices...I keep wondering when computer science got merged with home economics class :) ).
The general idea is that you restrict the class to a single instance by hiding the constructors and providing instead a function to get at "the" instance (optionally creating the instance on-demand if necessary).
If you do something that, then you can easily provide your own ToString() method that overrides the standard one.
Pete
.
- Follow-Ups:
- References:
- Making static class ToString() not possible, why?
- From: Zytan
- Re: Making static class ToString() not possible, why?
- From: Jon Skeet [C# MVP]
- Re: Making static class ToString() not possible, why?
- From: Zytan
- Re: Making static class ToString() not possible, why?
- From: Jon Skeet [C# MVP]
- Re: Making static class ToString() not possible, why?
- From: Zytan
- Making static class ToString() not possible, why?
- Prev by Date: Why doesn't C# allow incremental compilation like Java?
- Next by Date: Re: Multiple images in a PictureBox Control
- Previous by thread: Re: Making static class ToString() not possible, why?
- Next by thread: Re: Making static class ToString() not possible, why?
- Index(es):
Loading