There is no problem - the code is doing exactly what you've told it to!
You increment the Counter variable each time you create a new instance of the Program class. However, you never create an instance of the Program class - you just declare two variables which could potentially hold an instance of that class in the future.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
The problem is that in this case, you aren't creating any instances of your class, just the variables to hold instances. If Program was a struct rather than a class, then
would create instances - but they still wouldn't increment your counter, because value type constructions aren't implicitly called.
Program b = new Program();
Program c = new Program();
And your counter will be incremented as you expect because you are creating instances.
A variable isn't the same as an instance: think of a variable as a "parking space" - it can hold any Car object, but you can't drive the space down to the shops! The parking space is the variable, the instance is the actual Car it holds.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
staticvoid Main(string args)
var a = new App();
var b = new App();
Needless to say that abusing it as a global variable is an anti-pattern. I don't know what you are trying to do, but this seems like the wrong way.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
hello every one,
I have a problem with my program,
I can select a image from one folder in open dialog but I can't move the image to be processed in another directory.
so pleas help me..
this is my program
public partial class Form1 : Form
private TransferFile transferFile = new TransferFile();
hello,i have question as follows.
for example, I want to call fun1, then introduce vary x, and function as vary(fun2 or fun3), fun2 and fun3 have different varies. In fun1, can call fun2 or fun3 according to reference.
I think delegate can solve it ,but fun2 and fun3 have different number input, how to do it?
delegate void call() //?
fun2(y) or fun3(y,z)?
This code makes no sense: you call method 'fun1 with two arguments, but method 'fun1 takes no parameters. All your methods, and the delegate, are defined outside the scope of the Main method: what is the enclosing Class ?
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
i am sorry,indeed i am a beginner.
I don't know how to meet my requirement. My requirement as follows:
I want to code an optimization algrithm function to calculate Minimized value. It can input function that needed optimization, like fun2 or fun3 ,etc... that i said. It means if i input fun2 to optimization function ,it can search fun2's Minimized value, if input fun3, it can search fun3's Minimized value.But fun2 and fun3 or other functions don't have same style input variable,their input variable style and number is not same.
how can i realize it?
Thank you very much,it 's near my requirement.
But one more requirement is that:
static void fun1(int x, Action call)
take fun3(y,z) for example, call() is run fun3(y,z).
but if i want to run fun3(x,z) ,how to realize it? you know ,i want to change y value in fun1 to call fun2(int y) or fun3(int y,int z),because my code use loop to change y value in fun1,to let fun2 or fun3 be a minimum value.
Great Job!!! Thank you very much.
And i have other question bothering me.
I have to use chart control to plot 10 series including 1000 points per series in one chartarea. But after ploting, mouse move or zoom in or ContextMenuStrip operation is very slow and delay. I think maybe paint problem.
When i ask before, i get the answer is point number is too big.
But i found that if i plot 200 series with 1 point for example as follows, the operation is also slow. How can treat it?