![]() |
Understanding the default code
Looking ahead into a simple Windows project that would just have a button on a form, and then when the button is clicked I would display a message or something. When I double-click the button the following code is presented in the editor window:
:
namespace Nice_GirlCan someone explain what some of that stuff means? I know what a namespace is so I'm okay with that, but the rest of it nope. I've looked on the web but can't seem to find any clear cut answers that aren't way over my head. |
:
does that help? |
A little. The "partial" keyword means something about your class definition being able to be split into multiple physical files? That's what one site said about them anyway.
Why is it written Form1 : Form and not Form1? Then moving on, is Public Form1() known as what is called a constructor? Although I really don't know what a constructor is or what purpose it serves. Then I guess InitializeComponent() must be some kind of method. Finally, what is the object sender, EventArgs e mean? I assume that must be some kind of parameter list, but if you could elaborate a little. |
ok first, i dont know what "partial" means.
second, the ": Form" after Form1 makes it realize that this is a form being compiled. If i'm wrong, someone please correct me. All a constructor is, is a method that creates a new instance of an object. Yes InitializeComponent() is a method, that is built in. and sorry, but I have no idea what object senger, EventArgs e means. |
Quote:
|
Actually I have the C# Primer Plus book by Klaus Michelsen. But in that book he just deals with the core language.
|
I read about the partial classes on www.devx.com/dotnet/Article/22603/1954?pf=true.
|
Quote:
Quote:
When button one gets clicked, the code in the brackets gets triggered. The object sender, EventArgs e are the arguments. In this case, the event takes on 2 arguments. It takes sender (which is an object), and e, which is a EventArgs. Everything in the whole system namespace (from what I remember) can be represented as an object (correct me if I'm wrong?). Eventargs e provides ( as described) extraarguments, for the event. Not very decriptive on my part I know. You have to explore it yourself. It all comes down to the hierarchal tree. Use the following code to see what object gets returned when you use this code under the button click event: :
MessageBox.Show(sender.ToString());Another note on arguments. it's no different from the following code: :
public void test(string MyString1, string Mystring2){}the above code is a function that does not return a value, but takes 2 strings as arguments. Anyways, I hope that helped. |
| All times are GMT -5. The time now is 2:03 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC