Click here to Skip to main content
15,887,676 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to bind control’s properties to variables in C#? Pin
PomaPomaPoma3-Feb-10 10:09
PomaPomaPoma3-Feb-10 10:09 
GeneralRe: How to bind control’s properties to variables in C#? Pin
Not Active3-Feb-10 10:17
mentorNot Active3-Feb-10 10:17 
QuestionC# code clean up and improvement Pin
eeffoc423-Feb-10 5:20
eeffoc423-Feb-10 5:20 
AnswerRe: C# code clean up and improvement Pin
Luc Pattyn3-Feb-10 5:26
sitebuilderLuc Pattyn3-Feb-10 5:26 
GeneralRe: C# code clean up and improvement [modified] Pin
eeffoc423-Feb-10 5:50
eeffoc423-Feb-10 5:50 
GeneralRe: C# code clean up and improvement Pin
Luc Pattyn3-Feb-10 6:26
sitebuilderLuc Pattyn3-Feb-10 6:26 
GeneralRe: C# code clean up and improvement Pin
eeffoc423-Feb-10 9:17
eeffoc423-Feb-10 9:17 
GeneralRe: C# code clean up and improvement Pin
Luc Pattyn3-Feb-10 9:54
sitebuilderLuc Pattyn3-Feb-10 9:54 
you're welcome.

eeffoc42 wrote:
4. This was done for a few reasons,
>1. I was having problems formatting the output and


Huh? you create a string, enqueue it, dequeue it, and add it to the ListBox.
Creating the string and adding it to the ListBox would result in the same net result, the queue doesn't change anything here.

eeffoc42 wrote:
7. I do have a method that handles exceptions


I'm not particularly fond of MessageBox, I tend to include reporting functionality (progress, status, errors, ...) in my active form, but that is a matter of taste. I only consider MessageBoxes acceptable for the very exceptional stuff, most certainly not for progress! It is not my job to tell the computer to go and continue all the time...


eeffoc42 wrote:
1. Not sure how to approach this

eeffoc42 wrote:
2. Not entirely sure how to do this


Not tested, just indicative:
public List<string> Gather() {
    List<string> list=new List<string>();
    for(int i=0; i<10; i++) list.Add("string number "+i.ToString());
    return list;
}
public void ShowResults(IEnumerable<string> list) {
    foreach(string s in list) myListBox.Items.Add(s);
}


and
public void Gather(Action<string> reporter) {
    for(int i=0; i<10; i++) {
        string s="string number "+i.ToString();
        if (reporter!=null) reporter(s);
    }
}

public void myReporter(string s) {
    myListBox.Items.Add(s);
}

public void GatherAndReportIntertwined() {
    Gather(new Action<string>(myReporter));
}


both examples illustrate separation of what you gather and how you present the results.

eeffoc42 wrote:
what part to start on first?


that's up to you. Most issues are minor edits, replacing the queue stuff by a delegate-based approach is the only major one. It will shorten and clarify your code a lot, especially if you create and use a simple report method; example:

public void report(string s) {
    if (reporter!=null) reporter(s);
} 

where reporter now is a class member that gets initialized by this.reporter=reporter; at the start of Gather().

Smile | :)

Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
[The QA section does it automatically now, I hope we soon get it on regular forums as well]


AnswerRe: C# code clean up and improvement Pin
Md. Marufuzzaman3-Feb-10 6:27
professionalMd. Marufuzzaman3-Feb-10 6:27 
Questionasalamalikum! Pin
ayeshazahoor3-Feb-10 4:43
ayeshazahoor3-Feb-10 4:43 
Questionhello every one Pin
japrasath3-Feb-10 4:03
japrasath3-Feb-10 4:03 
AnswerRe: hello every one Pin
tonyonlinux3-Feb-10 4:13
tonyonlinux3-Feb-10 4:13 
AnswerRe: hello every one Pin
Not Active3-Feb-10 4:33
mentorNot Active3-Feb-10 4:33 
AnswerRe: hello every one Pin
Abhinav S3-Feb-10 5:47
Abhinav S3-Feb-10 5:47 
AnswerRe: hello every one Pin
Wamuti3-Feb-10 9:07
Wamuti3-Feb-10 9:07 
QuestionInserting a record into a Multi-table database using linq to sql in c# [modified] Pin
tonyonlinux3-Feb-10 3:58
tonyonlinux3-Feb-10 3:58 
AnswerRe: Inserting a record into a Multi-table database using linq to sql in c# Pin
Not Active3-Feb-10 4:35
mentorNot Active3-Feb-10 4:35 
QuestionForms Slowness Pin
Syed Shahid Hussain3-Feb-10 3:09
Syed Shahid Hussain3-Feb-10 3:09 
AnswerRe: Forms Slowness Pin
OriginalGriff3-Feb-10 3:19
mveOriginalGriff3-Feb-10 3:19 
GeneralRe: Forms Slowness Pin
Syed Shahid Hussain3-Feb-10 3:28
Syed Shahid Hussain3-Feb-10 3:28 
GeneralRe: Forms Slowness Pin
OriginalGriff3-Feb-10 3:39
mveOriginalGriff3-Feb-10 3:39 
GeneralRe: Forms Slowness Pin
Syed Shahid Hussain3-Feb-10 3:48
Syed Shahid Hussain3-Feb-10 3:48 
GeneralRe: Forms Slowness Pin
Luc Pattyn3-Feb-10 3:51
sitebuilderLuc Pattyn3-Feb-10 3:51 
GeneralRe: Forms Slowness Pin
OriginalGriff3-Feb-10 3:59
mveOriginalGriff3-Feb-10 3:59 
GeneralRe: Forms Slowness Pin
Syed Shahid Hussain3-Feb-10 4:46
Syed Shahid Hussain3-Feb-10 4:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.