static

c#: Inherited/interface static member?

Is there a way to require that a class have a particular abstract member? Something like this: public interface IMaxLength { public static uint MaxLength { get; } } Or perhaps this: public abstract class ComplexString { public abstract static uint MaxLength { get; } } I'd like a way enforce that a type (either through inher...

Static Constructor & Singleton class

I have an object cache which implements the Singleton design pattern. My approach to singleton was always to lazy load the static instance when the property is first accessed. public static Widget Instance { get { if(instance==null) instance = new Widget(); return instance; } } However, I know that this ap...

Explanation of how classloader loads static variables

Ok so this is a newbie question on java, but i can't seem to get my head around it. I have the following code inside my class private static final String [] LIST_CODE = gerarListCode(); private static final int [][] LIST_INTEGER = new int [][] { {947,947}, {110,103}, {947,958}, {110,120}, {947,954}, {103,107}...

Should I make this XmlSerializer static?

I've got a class which uses an XmlSerializer in its Read/WriteXml methods. The Serializer is currently private readonly. public class Foo : IXmlSerializable { private Bar _bar = new Bar(); private readonly XmlSerializer serBar = new XmlSerializer (typeof (Bar)); public void WriteXml (XmlWriter writer) { serBar.S...

static class availability problem

Can anyone help with this I really can't see what is wrong. I have a set of classes all in the same namespace and assembly. One of these classes is static. Since it is declared in the same namespace and assembly as the other classes I would expect it to be accessible to them all. However it turns out it is accessible to all bar one ...

Share imagelist in .Net Winforms application

I want to have ONE instance of an image list that I want to share over all the forms in my application(s) (icons for the toolbar). I've seen the question asked before and people came up with a user control (which is no good, since it will create multiple instances of the imagelist and thus create unnecessary objects and overhead). Desig...

what's the best pattern or method to load a static cache?

Let's say I have the following (assume restricted to java 1.4 so no generics) : public class CacheManager { static HashMap states; static boolean statesLoaded; public static String getState(String abbrev) { if(!statesLoaded) { loadStates(); } return (String) states.get(abbrev); } ...

Do you really need stateless session beans in this case?

We have a project with a pretty considerable number of EJB 2 stateless session beans which were created quite a long time ago. These are not the first-line beans which are accessed from our client via RMI, rather they are used by that code to perform specific functions. However, I've come to believe that there's nothing to be gained by h...

When should we create a static class?

How can we distinguish to create a class which is static? ...

Find out if a method exists in a static class.

I want to check is a function exists in a library that I am creating, which is static. I've seen function and method_exists, but haven't found a way that allows me to call them in a relative context. Here is a better example: class myClass{ function test1() { if(method_exists("myClass", "test1")) { echo "Hi"; ...

How can I create a totally dependent SWF from an existing dynamic one?

I manage a website that has ModX and for some reason I just can't get dynamic SWF files to load. This is not normally a problem as I have a Flash menu creator program that makes static SWF files. However, this new one only makes dynamic SWFs (ones that rely on external files and XML). I've tried making a Projector of the file but with th...

What is the point to a static method in a non-static class?

I have trouble understanding the underlying errors with the code below: class myClass { public void print(string mess) { Console.WriteLine(mess); } } class myOtherClass { public static void print(string mess) { Console.WriteLine(mess); } } public static class Test { public static void Main()...

what is the c# equivalent of public final static in java

In Java I can write: public final static MyClass foo = new MyClass("foo"); is there an equivalent in C#? ...

Static vs. non-static method 2

Possible Duplicate: Static vs. non-static method which one is better for a good design or are there any difference? or is it just up to the developer? class Foo { int x; void add(Foo* f1) //Method 1 { x += f1->x; } static void add(Foo* f1, Foo* 2) //Method 2 { f1->x = f1->x + f2->x; ...

Are there equivalents to "this" for static variables in c#

I was wondering if I can make my code clearer by indicating one variable is a static class variable. If it wasn't static I could use this.variableName, and everyone would look at it and immediately know that. I know I could adopt a naming convention like s_variableName, but that seems a little odd to me and increases the learning curve ...

Can source server (Debugging Tools for Windows) be used with static library projects?

Hi, I can't find a way to use the source server tools from the Debugging Tools for Windows on a static library project, which is built separately from the solutions actually using that library: The output of "ssindex.cmd" always displays "zero source files found" for the PDB file generated for the library (using compiler options /ZI an...

Behaviour of static variables in dynamically linked libraries (C/C++)

As discussed here, a static variable is stored in the .BSS or .DATA segment. Where is this memory stored if the static variable is inside a function that's in a dynamically linked library ? Does storage for this variable get allocated in the .BSS or .DATA segment of the linking process at the time of linkage ? ...

In php how can I make sure that static variables declared in a function will not re-initiated whenever the function is called?

It seems that a static variable declared in a function is re-initiated whenever the function is called, how can I use the function in a way that re-calling the function will re-use the static parameter? I defined the function 'testStatic' in static.php here is static.php: <?php function testStatic() { static $staticV = 0; echo...

static constructors in C++? need to initialize private static objects

I want to have a class with a private static data member (a vector that contains all the characters a-z). In java or C#, I can just make a "static constructor" that will run before I make any instances of the class, and sets up the static data members of the class. It only gets run once (as the variables are read only and only need to be...

what is the c# equivalent of static {...} in Java?

In Java I can write: public class Foo { public static Foo DEFAULT_FOO; static { DEFAULT_FOO = new Foo(); // initialize DEFAULT_FOO.init(); } public Foo() { } void init() { // initialize } } How can I get the same functionailty in C# (where static members are initialized ...