|
I know, I wouldn't use it but couldn't find the method so I pointed him in the right direction.
|
|
|
|
|
You need to assign the loop code to a thread...
|
|
|
|
|
Calling the Refresh method should resolve your problem:
messageRTB.Text += " Please Wait, this will take a while...";
messageRTB.Refresh();
Thread.Sleep(5000);
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hey, I'm new to C# and I have a question regarding enumerators I was hoping someone can answer for me. My question is what is the purpose of giving an enumerator a base type if you still have to explicitly convert it?
Thanks, a bunch.
Terrance C.
|
|
|
|
|
Terrance Copling wrote: My question is what is the purpose of giving an enumerator a base type if you still have to explicitly convert it?
I'm not quite sure I understand your question. Are you asking what is the purpose of IEnumerable and IEnumerator ?
They exist to tell the framework that the class in question can be enumerated in a foreach loop.
IEnumerable contains the method GetEnumerator() which retrieves an instance of a class that implements the IEnumerator interface. The IEnumerator interface includes all the information needed to loop over an object of the associated IEnumerable class.
Does this help?
|
|
|
|
|
I'm sorry. For example, if I have the following;
enum Cars : int
{
Mercedes = 1
Chrysler
Honda
Nissan
}
(Main)
To get the value to print out I would have to type:
Console.WriteLine("Value of Honda is {0}", (int)Cars.Honda);
Why can't I just write: Console.WriteLine("Value of Honda is {0}", Cars.Honda);
Is this a silly question?
Terrance C.
|
|
|
|
|
Terrance Copling wrote: Why can't I just write: Console.WriteLine("Value of Honda is {0}", Cars.Honda);
Because that would print out "Value of Honda is Honda". I presume the ToString on an enum is set to print out the name of the value rather than the value itself. Hence the need to cast it to an int .
Terrance Copling wrote: Is this a silly question?
People tell me there are no silly questions.
I don't know if this really helps. It is a bit of a circular answer: It does it this way because it does.
I've never found this design to be a problem or limiting factor in all the time I've used C# (i.e. since it was in beta in 2001)
|
|
|
|
|
Colin Angus Mackay wrote: I presume the ToString on an enum is set to print out the name of the value rather than the value itself. Hence the need to cast it to an int.
Yep that's what's happening, if the method doesn't understand what type it is it defaults to object and uses the ToString value for the representation.
|
|
|
|
|
In general we don't care that much what the underlying value of an enum is.(We are more interested in readability for instance).
When you start out in c# you will often have these moments when you don't see why you have to do things, especially when those things involve casting. The aim here is to remove ambiguity. I would say that most times when i use an enum i would want to pass Cars.Honda and not the value 3.
How about the method GetInCar()
we might declare it as
public void GetInCar(Cars carToGetIn)<br />
{<br />
this.CurrentCar = carToGetIn;<br />
}
If you want to get in the Honda we would call the method
GetInCar(Cars.Honda);
If we want to find which car we're in
public Cars WhichCarAmIIn() <br />
{<br />
return this.CurrentCar;<br />
}
If we've done everything right this should return Cars.Honda
We never really need to know what the value is for most stuff that we do. There are times that we will need to know, but often it's enough to know that the values are unique for each item
HTH
Russ
|
|
|
|
|
Thanks everyone for your explanations. Russ thanks for your explanation. You brought back some memories that I had from my old C++ classes.
It's funny but I don't think VB.NET prints enums out the same as C# does. I started out in VB and I occassionally used enums but I always used them is SELECT CASE statement getting the value rather than the actual string value. Interesting, I know the two languages are different but didn't think the enums would differ that much. Thanks again.
Terrance C.
|
|
|
|
|
You should be able to do the same thing in both c# and VB. I guess that VB does some sort of auto casting when you try to compare an enum with an int. c# won't do the cast for you but you could do it yourself.
switch(CarType)<br />
{<br />
case Cars.Honda:<br />
DoHondaThing();<br />
case Cars.Jaguar:<br />
DoJaguarThing();<br />
}<br />
<br />
switch((int)CarType)<br />
{<br />
case 1:<br />
DoHondaThing();<br />
case 2:<br />
DoJaguarThing();<br />
}
Both are syntactically valid but i know which i'd rather be reading 6 months after I coded it. Also if i add an item at position 2 making Jaguar = 3 without changing the second switch statement we could be in trouble.
Russ
|
|
|
|
|
I'm trying to write some code that pops up a little borderless form next to the notification area when a notification icon is double clicked. The code is going to be used in the office and most people here have 2 monitors and several people have left / right / top taskbars.
How do i find the current location of the SysTray?
Thanks
Russell
-- modified at 10:26 Wednesday 14th February, 2007
|
|
|
|
|
Try the static Cursor.Position property. I think it would be the easiest way to open the form where the user performed the double-click.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi,
I want to create an entry of my software on the left-click menu of microsoft office documents. (i.e when you press left-click on a word document you see "Print", "Open" etc. in the menu.
Please let me know if my question is not clear enough, or if you have a solution for it.
Thank you!
Nauman
|
|
|
|
|
I want to install a specific font with a Windows application. I have added the font to the deployment project, but do not know how to target the font to the C:\Windows\Font folder. Thanks.
|
|
|
|
|
how about copying it there?
|
|
|
|
|
Will not work, it has to be installed!
I'm also looking for a code solution fro that.
|
|
|
|
|
Hi, I need a FTP client and FTP server source code for Linux, please, help me.
|
|
|
|
|
err..since C# is a microsoft language this would be the LAST place you should ask in o_O
|
|
|
|
|
Have people never heard of Google[^]?, I just typed in Linux ftp server and that was the third hit.
|
|
|
|
|
I am running through a list (named sublist in my code) of lines checking to see if any match where the user has clicked. At the moment I am using the following code which does work
bool test = false;
int hold;
int i =0;
while (!test && i < sublist.Count)
{
test = sublist[i].DeleteLine(new Point(e.X, e.Y));
if (test)
hold = i;
i++;
}
If there is a match I will delete the line from the list, so I need to know the location where the match occurred. I would like to just be able to use i, but either I get an out of bounds error or miss the last line in the array. I have looked at do/while with the same results. With for/foreach I either go through the whole list and still need to remember where the match occurred or use break which I understand is poor coding practice in a for loop.
My question is, is there a way to not have to use the variable hold with a do/while or while loop?
|
|
|
|
|
Try looping backwards from sublist.count to 0.
|
|
|
|
|
there is nothing wrong with using break in this case, try this;
int i=0;
do
{
if (sublist[i].DeleteLine(new Point(e.X, e.Y)))
break;
} while (i++ < sublist.Count);
If you are determined not to use a break you can do something like this, but I think the first example is easier to read and understand.
int i=0;
do { } while ( !sublist[i].DeleteLine(new Point(e.X, e.Y)) && (i++ < sublist.Count ));
Tara
|
|
|
|
|
try this:
int i=0;
do { } while ( !sublist[i].DeleteLine(new Point(e.X, e.Y)) && (i++ < sublist.Count ));
actually I would prefer to use the break statement, it is easier to understand
int i = 0;
do {
if ( sublist[i].DeleteLine(new Point(e.X, e.Y) ) )
break;
} while (i++ < sublist.Count);
Tara
|
|
|
|
|
Hi,
you have an index (i), an initialisation, a continuation test, and an increment.
That is called a for loop.
To avoid needing the index outside the for loop, do the delete inside it,
something like:
for (int i=0; i<count; i++) {
if (some test) {
do whatever needs to be done to item i
break;
}
}
There is nothing wrong with break; it is intended to be used for an early termination
of a loop, so it is a natural here.
Luc Pattyn
|
|
|
|