|
It seems the foreach inside each other doesn't work..
foreach statement cannot operate on variables of type 'System.Web.UI.Control' because 'System.Web.UI.Control' does not contain a definition for 'GetEnumerator', or it is inaccessible
Is that right?
|
|
|
|
|
Oops, made a slight error it should be:
foreach(Control d in c.Controls) {<br />
...
And it then should of course be:
if(d is textbox)
...
not if(c is textbox)
foreach(Control c in Page.FindControl("MyPage").Controls) {
if(c is TextBox)
c.Text = "";
if(c is Panel)
foreach(Control d in c.Controls) {
if(d is TextBox)
d.Text = "";
}
}
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
Hey, that works like a dream, thanks a lot for that.
I now know something I didn't, what more can I want.
Thanks again.
Harvey
|
|
|
|
|
Hi all,
I would like to know how I can get out of this loop the first time the condition is true?
public string DirSearch(string sDir)
{
try
{
string compareString = "";
foreach ( string dir in Directory.GetDirectories(sDir))
{
foreach ( string file in Directory.GetFiles(dir))
{
compareString = file.Substring(file.LastIndexOf("\\"),(file.Length-file.LastIndexOf("\\")));
if (globalFileName == compareString.Substring(1, (compareString.Length - 1)))
{
return file;
}
}
DirSearch(dir);
}
return "";
}
catch (System.Exception excpt)
{
MessageBox.Show(excpt.Message,"Exception Occured",MessageBoxButtons.OK,MessageBoxIcon.Error);
return "";
}
}
Many Thanks
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
AFAIK the only way to break out of foreach look is with a "break" statement.
There are some interesting discussions, and yes blogs, around the net about foreach versus for loops in .NET. You might want to check them out.
|
|
|
|
|
Hi Mike,
Thanks for your reply and comments but, break does not work. I have tried it without success.
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
Programm3r wrote: Thanks for your reply and comments but, break does not work. I have tried it without success.
works for me
string[] test = {"help","me","with","for","loops"};
foreach(string t in test)
{
Console.WriteLine(t);
if( t.Equals("for"))
break;
}
|
|
|
|
|
Programm3r wrote: if (globalFileName == compareString.Substring(1, (compareString.Length - 1)))
{
/* File was found */
return file;
}
if you mean this bit, it already does by virtue of the return keyword.
In general you can break a look by using the break keyword. For completeness you may also like to look up the continue keyword in c#
|
|
|
|
|
you can use also "goto"
short example:
string filename = "";
for(int i = 0; i < 10; i++)
{
if(i == 3)
{
filename = "path"
goto FileHasFounded;
}
}
FileHasFounded:
MessageBox.Show("file name is this: " filename);
break don't work in this case because you have two loops. and it will break only from one loop
hope it will help.
respect.
spaps
|
|
|
|
|
Shpendh wrote: you can use also "goto"
The number of valid uses of goto in a language as rich as C# is negligible. In fact I can't think of any time I've used a goto in any language in the last 10 years.
Upcoming FREE developer events:
* Developer! Developer! Developer! 6
* Developer Day Scotland
My website
|
|
|
|
|
Exactly what I was thinking.
Number of times ive used goto in c#: zero!
|
|
|
|
|
Breaking out of a couple of nested loops? (I always wanted to be able to name loops, or do a break(2); or something similar)...
You're right though - theres very very few usages of goto that are "legitimate".
|
|
|
|
|
if (usingGoto)<br />
{<br />
goto jailAndDoNotPassGo;<br />
}
|
|
|
|
|
Other than in a C# switch?
|
|
|
|
|
PIEBALDconsult wrote: Other than in a C# switch?
Nope. I don't use gotos in switch statements - although I am aware that it is one of the few valid places you might consider using them.
In fact I don't use switch statements all that often as I generally (but not always) consider them a sign of a poor design. Although I think that is just because I've seen them used badly in so many situations.
Upcoming FREE developer events:
* Developer! Developer! Developer! 6
* Developer Day Scotland
My website
|
|
|
|
|
i didn't say that "goto" is the only one choise in this solution, i wanted to help him with one of the solution, i never didn't use "goto" in my application but i have only learned about it.
but anyway sorry,
maybe this example will help,
string filename = "";
bool isFound = false;
foreach(string str in strColl)<br />
{<br />
if(!isFound)<br />
{<br />
foreach(string str2 in strColl2)<br />
{<br />
if(str2 == "founded")<br />
{<br />
filename = str2;<br />
isFound = true;<br />
break;
}<br />
}<br />
}<br />
else<br />
{<br />
break;
}<br />
}
hope this will help,
spaps
|
|
|
|
|
According to the C# 2.0 standard ISO/IEC 23270
15.9.1 The break statement
....
....
When multiple switch, while, do, for, or foreach statements are nested within each other, a break statement applies only to the innermost statement. To transfer control across multiple nesting levels, a goto statement (§15.9.3) shall be used.
So there you are, it's official, use a goto.
Is there a smiley for "light the blue touchpaper and stand well back"?
|
|
|
|
|
Hi,
We are thinking about starting a new project but are worried about the take-up of .NET Framework 3 within businesses. Is is it possible to have a WCF server application connecting to a client over Binary NetTcp to talk to a .NET Framework 1.1 / 2 client?
Thanks
|
|
|
|
|
If you mean can your WCF service be consumed by a none-WCF source then the answer is yes. WCF allows you to expose your service through a wide variety of protocols, one of which should suit your needs.
|
|
|
|
|
I made it clear that I'm using netTCP, it's my understanding that it's not possible to build a non-WCF client for protocol but I'm wondering if anyone knows a way around it.
|
|
|
|
|
How to open .tif file in VC++ MFC from file open menu?
|
|
|
|
|
This is the wrong forum for this question. Please ask this here[^].
|
|
|
|
|
Hi!!
I have some problems.
Actually I do a survillance using webcam project(using c#)
I need to use my webcam to monitor activities on somewhere
recording and connect it to server .
Webcam can use more than one & client must be a windowsservice for survillance.
this is activities that I do
client:
1.Recieve a remote from server.
2.connect to webcam & capturing using Webcam_Capture.dll.
3.send it to server using RTP.
Server:
1.Setting & Remote to client.
2.Save picture for client.
3.Show Picture.
and I have a problem now because
First in Client I use Windows Form and now I need to change this code to be a windowsservice.
This service need to capture a picture from webcam by using Webcam_capture.dll
So I create a variable From Webcam_capture.dll but this class reference System.Windows.Form.usercontrol
that must add a reference to System.Windows.Form .
How can I do for this problem??? Please Help me !!!
thanks,
PZ
|
|
|
|
|
Ok, this is just a tiny bother, but I'll ask anyway. While debugging is sometimes get status messages on my console that look like this:
The thread 0x15cc has exited with code 0 (0x0).
This is nice in itself, but since I've got a whole bunch of threads running I'd like to see what thread is done running.
I could of course use a simple Debug.WriteLine("The thread " + Thread.CurrentThread.Name + " has exited") statement to see what thread has completed.
But I'm wondering if VS2005 can't be set to automatically replace the threadnumber with the thread name I assigned it?
Standards are great! Everybody should have one!
|
|
|
|
|
AFAIK it will not be possible since the Windows kernel does not hold thread names.
Have you ever seen a utility (TaskManager/SysMonitor/SystemInformation/...) show thread names?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|