|
It works because you aren't modifying anything the iterator needs to worry about: neither the key nor the value are being modified in any way (since they are a struct you can't change and a reference). You can modify the content of the object the reference "points" to very easily and legally inside the foreach, because you aren't trying to change the values in the collection you are iterating over.
List<MyClass> list = new List<MyClass>();
for (int i = 0; i < 5; i++)
{
MyClass mc = new MyClass() { s = i.ToString() };
list.Add(mc);
}
foreach (MyClass mc in list)
{
mc.s = mc.s + " changed!";
}
foreach (MyClass mc in list)
{
Console.WriteLine(mc.s);
}
Will give you:
0 changed!
1 changed!
2 changed!
3 changed!
4 changed! But obviously trying to change the actual value will give you a compilation error:
foreach (MyClass mc in list)
{
mc = new MyClass() { s = mc.s + " Changed again!" };
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thanks Grif ! I don't know my trying to grok this slips off me brain like noodles slip off a spoon. These memories I have of using exotic means to modify collections to avoid error ... I believe one of the memories is of a technique you posted years ago ... something about iterating from end of the collection to the start. Alas, memory, unreliable companion as age ticks off my telomeres
cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
Off topic, but on subject - did your op get cancelled again?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
BillWoodruff wrote: something about iterating from end of the collection to the start.
You usually do that if you're removing items from the collection within a for loop, and you don't want to skip any elements.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi ,
I am exporting files using C# process object , I need to only send and email once all files export get finished. when i execute below program i immidiatly receive an email even though file export is in progress at background process object.
I have added WaitForExit() after process.start(). Am i missing something in below code? please help.
ProcessStartInfo objProcStartInfo;
Process objProcess;
Email objSendUnloadEmail = new Email();
objProcStartInfo = new ProcessStartInfo("db2cmd.exe", "-c db2 connect to " + strMasterdatabaseName + " user " + strserviceAccountUserName + " using " + strserviceAccountPassword + "&db2 -f " + strexportFilePath + " > " + strexportLogFilePath + "");
objProcStartInfo.RedirectStandardOutput = false;
objProcStartInfo.UseShellExecute = false;
objProcStartInfo.CreateNoWindow = false;
objProcess.StartInfo = objProcStartInfo;
//Starting Process to export files on directory.
objProcess.Start();
//Wait For Next Action Till File Export Get Completed..
objProcess.WaitForExit();
objSendUnloadEmail.SendEmailNotificationForUnload();
|
|
|
|
|
Try replacing -c with -w :
- -c | /c
- Execute command following the -c option in a new DB2 command window, and then terminate. For example,
db2cmd -c dir causes the dir command to be invoked in a new DB2 command window, and then the DB2 command window closes. - -w | /w
- Execute command following the -w option in a new DB2 command window, and wait for the new DB2 command window to be closed before terminating the process. For example,
db2cmd /w dir invokes the dir command, and the process does not end until the new DB2 command window closes.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for reply , If i add -w then i got 2 email one at start and one after completion of process. However in this case i need to manually close DB2 CLP window and then second email triggered out.
I need to send out email notification once all file export completes.
|
|
|
|
|
Hi,
I am still unable to control on Process.Waitforexit(); It will immidiatly send an email even though file export in progress.
its not working after Process.Start();
Am i missing something in below code?
objProcStartInfo = new ProcessStartInfo("cmd.exe");
objProcStartInfo.RedirectStandardOutput = true;
objProcStartInfo.UseShellExecute = false;
objProcStartInfo.CreateNoWindow = false;
objProcess.StartInfo = objProcStartInfo;
//Starting Process to export files on directory.
objProcess.Start();
//Wait For Next Action Till File Export Get Completed..
objProcess.WaitForExit();
objSendUnloadEmail.SendEmailNotificationForUnload();
please advise
|
|
|
|
|
Well, this article[^] seems to suggest that you need to use both options (-c and -w ) at the same time.
objProcStartInfo = new ProcessStartInfo("db2cmd.exe", "-c -w -i db2 connect to " + strMasterdatabaseName + " user " + strserviceAccountUserName + " using " + strserviceAccountPassword + "&db2 -f " + strexportFilePath + " > " + strexportLogFilePath + "");
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Database system used: Oracle11g /ADO.net
Hi,
in the dataset Wizzard for the TableAdapter, the option "Create methods to send updates directly to the database" is disabled. The database table is a single Oracle table that is simple queried with Select *, and has a PK with IDENTITY column.
Oddly, the update Anwweisung is generated, and the update also works. The DB has added the record and increments the PK value. However, the IDENTITY column is not displayed in the DataGrid / no refresh - what is the real problem.
Question: what could be wrong? How can the Identitiy value to retrieve updated / displayed?
LG
Nicole
|
|
|
|
|
You can start by replacing the SELECT * with a SELECT columnList.
The remaining functions will be generated using the column list.
|
|
|
|
|
I have the following code C# 2008 want to switch to the C#2005 Net2.0 after his move has been an error, thanks to the help available tracks.
[CODE]
//C# 2008
namespace Example1
{
public partial class Form1 : Form
{
Control draggingControl = new Control{ BackColor = Color.Green, Visible = false }; // warning error here
public Form1()
{
InitializeComponent();
// ...
}
// ...
}
}
[/CODE]
[CODE]
//C# 2005
//...
Control draggingControl = new Control();
draggingControl.BackColor = Color.Green; // warning error here
draggingControl.Visible = false; // warning error here
//...
[/CODE]
|
|
|
|
|
is it showing warnings or errors?
Any chance of getting to see the error?
|
|
|
|
|
quick question but what is Control ?
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
|
You have to rewrite the code. The code that's throwing these errors is using features of C# that were not around in 2005. In your examples, it's using a shortcut to setting properties after creating an instance of Control. You just have to break those lines inside the curly braces out into their own lines of code.
|
|
|
|
|
follow you fix solutions how not ? I'm secrets can you help me ?
|
|
|
|
|
Uhhh...Yoda just read that and went "What?"
If you're asking me to rewrite the code for you,that's not going to happen. I've got my own code to write and I've got a few hours work left before I can go to sleep tonight.
|
|
|
|
|
no need to rewrite the code, the original was this error No overload for 'splitter1_SplitterMoving' matches delegate 'System.Windows.Forms.SplitterCancelEventHandler' you fix this ?
|
|
|
|
|
No, I can't. You typed the code and I can't see it. The error is telling you that you've got the method header parameter list for "splitter1_SplitterMoving" wrong.
|
|
|
|
|
|
your link posted nearly identical to my questions, your example changes the mouse pointer while dragging splitBar, my questions changes the color tranparen for splitBar while dragging splitBar. Thank you send me the link for referenceing
|
|
|
|
|
You're welcome.
This space for rent
|
|
|
|
|
Hi,
I have currently migrated my application from 2.0 to 4.0. What i suggest is try to build your code from target framework 4.0 to 2.0, also setting up the cpu type as x86 for 32 bit platform.
Also, if there are some client side validation, you need to do settings in pages element attribute controlRenderingCompatibilityVersion=2.0 in web.config for the asp.net controls.
-Mayank Pant
|
|
|
|
|
Don't know why you're telling me this. I know how to convert code. If you meant to tell the OP how to do this, they won't get any notifications that you replied to another person.
This space for rent
|
|
|
|