|
-
October 8th, 2010, 03:49 PM
#2
Re: Beginning C#
 Originally Posted by rockking
hey everyone.
i am new to C# and i'm wondering if you can call a function or a method i guess is what its called but can i call one on load that has a "trigger" that runs a for loop to clear an array? heres what i have for my form load:[...]
Wait... What exactly is your question? Can you formulate it a bit better?
Does the code work for you? Have you tried it? Are there any errors? What are they saying?
Meanwhile, here are a few remarks:
 Originally Posted by rockking
[...] call a function or a method i guess is what its called [...]
Technically, in C# it's called a 'method', but traditionally such a construct is called a 'function' - a term that developers familiar with other languages might prefer, so you can say whichever you like better, people will understand.
 Originally Posted by rockking
Code:
if (gbl_trigger[0] == 0)
A word on that: don't give your variables such names, it's a bad practice. This could be OK for a small application where there would be only one trigger, and where it's meaning would be obvious. However, since you used an array, I'm guessing there's more than one trigger.
Imagine now that you suddenly decide to work on this new super-cool idea instead, and you start a different programming project, forgetting all about the current one for a while. Then, after some time, you decide it's time that your old still-on-hold projects gets some attention. But, hey, you weren't involved with it for some time, and you've forgot a thing or two. And than you see that, an go:
What to hell do gbl_trigger[0], gbl_trigger[1], gbl_trigger[2], ... trigger?
Then a (physical or virtual) pile of paper later, you realize it would have been much wiser if you gave the variable a more descriptive name in the first place.
(Not to mention what would happen if a different programmer was assigned with the task to continue developing your project.)
In relation to what I said, an array is probably not the best construct for the job: an enum would do much better.
 Originally Posted by rockking
Code:
if (gbl_trigger[0] == 0)
{
for (int i = 0; i < 10; i++)
{
operand[i] = 0;
button15.Text = i.ToString();
gbl_trigger[0] = 1;
}
}
It seams that you're trying to use gbl_trigger[0] to control the behavior of the loop and/or button. This looks very ugly.
But again, before I (or someone else here) can suggest a better approach, you need to rephrase your question into something more coherent, and give some more detail.
Last edited by TheGreatCthulhu; October 8th, 2010 at 03:55 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|