I have just come across a C# implementation detail that is not that obvious: static Variables in private Inner Classes ARE shared across several instances of the Outer Class!
Consider the following C# code, which existed in four of our WinForms Generator Templates:
private class FMainDS
{
public static {#DETAILTABLE}Table {#DETAILTABLE};
}
The public static DataTable is inside a private Inner Class that is part of a Form's Class. At first glance one is tricked into believing that although the 'static' keyword generally means that an instance of an Object is shared across all instances that reference it, it would not be the case here because it is part of a private Inner Class.
However, the instance of the DataTable Object is in actual fact getting shared across all instances of a Form! That fact caused Bug #874 (https://sourceforge.net/apps/mantisbt/openpetraorg/view.php?id=874).
Explanation for that behaviour: any static variable apparently exists only once in a special place on the Heap called 'HighFrequencyHeap' and it stays there until the AppDomain unloads - in other words until the application (here: the OpenPetra Client) is closed. It doesn't matter that it is declared in a private Inner Class of the Form Class - several instances of the Form Class will share the same DataTable as the static DataTable exists only once on the 'HighFrequencyHeap'. The apparent 'privateness' of the static DataTable is misleading!
In that circumstance it meant that the data of two or more instances of Forms based on Templates that used that code construct was actually shared between screens and caused the bug I mentioned above - pretty bad!
If the same code would be written in Java, the 'privateness' of the static Variable would be honoured and there would be several private static Variable instances, according to a blog post I found on the Internet. Maybe that's why I coded it a few years ago like that without thinking it could cause problems... having done Java programming for a few years.
Kind regards,
ChristianK