|
When do i need to use static methods and when non-static?
|
|
|
|
|
Oh Boy!
This is a bit fundamental, so I'll try to explain, but it is probably better explained in any of the many books on C# out there.
You can use a static method at any time: String.Format(...) is a static method. You give it as a command:
string s = String.Format("The result is {0}", 6 * 9);
and it evaluates to a string "The result is 54".
You use a non-static method when you want it work on an object: an instance of the class.
class Example
{
public string data;
public int CountChars()
{
return data.Length;
}
}
...
Example ex = new Example();
ex.data = "ABCDEFGHIJKLM";
int i = ex.CountChars();
...
ex is an instance of the Example class, so you can call CountChars on ex, and it will work on the data that is relevant to ex only. If you declare another variable ex2, then ex.CountChars() and ex2.CountChars() will return different values, depending on what data you have fed them.
Static methods can only access static data (and other static methods). In the Example class, you cannot define a static method that can access the "data" string, because it is non-static.
Does that make sense?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Why dont you write a new Class(lets say Common) and write your method there.
You can call this method from both form1 and form2
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Ok, But why it will be good to do it? Or at all to write with classes ( i mean for example if i have only one form)?
|
|
|
|
|
A form IS a class.
And he's right. If you're going to have methods that you need to call from multiple forms, then the logic place to put those methods would be the class that stores the data that your app is manipulating.
|
|
|
|
|
Currently I am downloading exchange data and using DataGridView to display the data in real time.
I have as many as 6 DataGrids with 5 columns and many rows each that are updated about twice a second. The problem is, if only a few cells are modified, most of the time the whole grid is repainted degrading the performance of the DataGrid! I know this to be the case as some flicker is evident on cells that are unchanged. I have also implemented a simple counter in the CellPainting event to verify this.
Does anybody know how to only paint cells that have changed and bypass the others?
john1166
|
|
|
|
|
I Created C# Program and add FREngin and FineReader Components. Can I Create default Textblock using block in the same project
|
|
|
|
|
? Can I see how have you done that ?
|
|
|
|
|
Can you please share the code with me.....i am searching for the same from long....not unable to get the information on google.
or you can suggest any site wherein i'll get the code
|
|
|
|
|
Is that possible to draw a graph by getting the values from database in windows application
|
|
|
|
|
|
|
I don't pretend to be a .NET expert, but I saw a query that the OP could have got an answer to by doing a painfully obvious search. Had to vent it out.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
hello
i have acrystalreport wich is conect to dataset
i have ther textboxes in section 1 and in section 4
i want to change the text of these textboxe by acode in run time
thanks
|
|
|
|
|
this.BackColor = colorDialog1.Color;
The main Form disapears and I have to go into the control bar at the bottom to find it.
How do I use ToolTip after I placed one onto the form as a non-visual component? How do I link it to a component & choose the text on the tip?
|
|
|
|
|
1) That's odd.
2) You should see a tooltip property on each control on the form.
|
|
|
|
|
not all components, such as oval VB shape, have tooltip property
|
|
|
|
|
|
watch ur language
|
|
|
|
|
Me? You're the one who said "VB".
|
|
|
|
|
1. Very very odd.
2. See below code. You can add this in the Form_Load Event.
toolTip1.AutoPopDelay = 5000;
toolTip1.InitialDelay = 500;
toolTip1.ReshowDelay = 500;
toolTip1.ShowAlways = true;
toolTip1.SetToolTip(this.btnRun, "Run");
toolTip1.SetToolTip(this.btnSelectDirToSave, "Select Output Directory");
toolTip1.SetToolTip(this.btnSelectTxtFile, "Select File to Process");
Hope this helps
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
PIEBALDConsult's reply answered my question, and I like to do things Visually using the editor anyhow
|
|
|
|
|
OK
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Hi!
I want to create few pannels(or any other object) that can be resized during run time.
Where can I see example of how to so.
I want that the mouse image will change to like in the design options in the .NET.
and so I will be able to controll few pannels(objects) in a form and to arrange them like I want .
Can some one show me a good example of this or code example.
Thanks
|
|
|
|
|
All you need to do is handle MouseDown, MouseUp, MouseMove and Paint events. Use Cursor property to change the cursor the way you like.
A bit of Googling will definitely give you some examples.
जय हिंद
|
|
|
|