Stupid question, I admit, but I'm quite new to C#: how can I write a method which accepts a single input parameter or a collection (e.g. array) of this parameter?
For example, let's say I have the method void MyMethod(int args). If I try to call the function with a single argument, like MyMethod(1234), the compiler obviously throws an error (int != int).
Overloading surely solves the issue (i.e. defining both void MyMethod(int args) and void MyMethod(int arg) and factoring out the common behaviour in a different private method) but is there a simpler way to do this?
Not at all, the solution is not very obvious. It might not be the entire solution, either.
You may want to overload that method with one that takes a single int, that way you can call it without having the compiler generate code that creates an array object every time (for the params array). Perhaps also add overloads that takes two and three parameters. The string.Concat method is overloaded in that way, for example.
Another overload that you may want to add is one that takes an IEnumerable<int>, that will work for an int, but also for other collections, like a List<int>.
Despite everything, the person most likely to be fooling you next is yourself.
i've made 3 methods and all the 3 methods are very heavy weight code as the download htmldata so applied threads on each method
ThreadStart starter = delegate
the method called here
progressBar1.Maximum = 100;
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
like this i've used 3 backgroundworker for all three methods separately
but still after the 3rd backgroundworker progressbar completes but the threads are still running so now i just want to know how can i make the UI thread responsive till all threads complete asynchronously.
Like Luc said, show some actual code. Also, how do you update the progress changed?, do you just pass it the current position in the iteration (i am guessing you're using a loop somewhere) or the actual percentage complete?, there is a difference.
error: object reference not set to an instance of an object
i'm getting this error. Please tell me how to correct this.
I've created a cellcontentclick event to get the row and column index where the checkbox is checked now i want to get the particular column value at this rowindex. As i want to get the address column data corresponding to the row in which checkbox is checked.
I'm writing application with very complex configuration (System.Configuration). I need to pass ConfigurationSection or ConfigurationElement inherited class object as a method argument, but method executes in separate AppDomain, since neither ConfigurationSection nor ConfigurationElement doesn't inherit from MarshalByRefObject classs I constantly get a SerializationException exception.
If I add SerializableAttribute to my configuration section it works, but I can't modify any variable.
Use the System.Diagnostics namespace. It includes the Process object that lets you run external programs.
Process p = new Process("notepad.exe");
It also includes methods such as WaitForExit() that tells your program to wait till the process it terminated, and also the 'StartInfo' that lets you set customized settings for running a program. Browse the namespace for more details.
Hi, I have a grid (4 rows x 5 columns). I need to sort grid by last column. But I want to trace what changes were made to row order. I need this info to:
1. Change row header's text 'cause it doesn't change automatically during sort.
2. Change the columns order, i.e. I have rows 1,2,3,4. After sorting I have 2,3,1,4. And I want my columns moved in that way: 2,3,1,4 (with DisplayedIndex property for example)