Click here to Skip to main content
15,905,419 members
Home / Discussions / C#
   

C#

 
GeneralRe: Comparing two ArrayLists ? [modified] Pin
User 665822-Apr-08 9:15
User 665822-Apr-08 9:15 
GeneralRe: Comparing two ArrayLists ? Pin
dennycrane22-Apr-08 9:35
dennycrane22-Apr-08 9:35 
GeneralRe: Comparing two ArrayLists ? Pin
User 665822-Apr-08 9:49
User 665822-Apr-08 9:49 
GeneralRe: Comparing two ArrayLists ? Pin
Guffa22-Apr-08 10:43
Guffa22-Apr-08 10:43 
GeneralRe: Comparing two ArrayLists ? Pin
dennycrane22-Apr-08 10:57
dennycrane22-Apr-08 10:57 
GeneralRe: Comparing two ArrayLists ? Pin
Christian Graus22-Apr-08 12:06
protectorChristian Graus22-Apr-08 12:06 
GeneralRe: Comparing two ArrayLists ? Pin
Guffa22-Apr-08 12:12
Guffa22-Apr-08 12:12 
AnswerRe: Comparing two ArrayLists ? Pin
Judah Gabriel Himango22-Apr-08 11:52
sponsorJudah Gabriel Himango22-Apr-08 11:52 
dennycrane wrote:
I´m making a spelling test.

If each of the words were spelled in the text box on it's own line, e.g.

[Textbox looks like this]
Foo
Bar
Bat
Baz
Then I'd code it up like this:
string[] correctlySpelledWords = { "foo", "bar", "bat", "baz" };      
string[] studentSpelledWords = textBox.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
bool studentSpelledEverythingCorrectly = ContainsSameElements(correctlySpelledwords, studenSpelledWords); 

....

bool ContainsSameElements(string[] first, string[] second)
{
    if (first.Length != second.Length)
    {
       return false;
    }

    for (int i = 0; i < first.Length; i++)
    {
        if (!string.Equals(first, second, StringComparison.InvariantCultureIgnoreCase))
        {
            return false;
        }
    }

    return true;
}
That ignores casing (e.g. spelling "Foo" as "foo" is acceptable).

FWIW, you can probably do this in less code using a LINQ query if you're using the latest version of .NET.



GeneralRe: Comparing two ArrayLists ? Pin
dennycrane22-Apr-08 12:25
dennycrane22-Apr-08 12:25 
GeneralRe: Comparing two ArrayLists ? Pin
Judah Gabriel Himango22-Apr-08 18:55
sponsorJudah Gabriel Himango22-Apr-08 18:55 
GeneralRe: Comparing two ArrayLists ? Pin
Anthony Mushrow22-Apr-08 12:14
professionalAnthony Mushrow22-Apr-08 12:14 
GeneralRe: Comparing two ArrayLists ? Pin
dennycrane22-Apr-08 12:40
dennycrane22-Apr-08 12:40 
GeneralRe: Comparing two ArrayLists ? Pin
Anthony Mushrow22-Apr-08 12:44
professionalAnthony Mushrow22-Apr-08 12:44 
GeneralRe: Comparing two ArrayLists ? Pin
dennycrane22-Apr-08 12:55
dennycrane22-Apr-08 12:55 
GeneralRe: Comparing two ArrayLists ? Pin
Anthony Mushrow22-Apr-08 13:01
professionalAnthony Mushrow22-Apr-08 13:01 
GeneralRe: Comparing two ArrayLists ? Pin
Guffa22-Apr-08 13:16
Guffa22-Apr-08 13:16 
GeneralRe: Comparing two ArrayLists ? Pin
Anthony Mushrow22-Apr-08 13:24
professionalAnthony Mushrow22-Apr-08 13:24 
GeneralRe: Comparing two ArrayLists ? Pin
dennycrane22-Apr-08 13:39
dennycrane22-Apr-08 13:39 
GeneralRe: Comparing two ArrayLists ? Pin
dennycrane22-Apr-08 13:32
dennycrane22-Apr-08 13:32 
GeneralOk, im confused. Pin
Anthony Mushrow22-Apr-08 13:37
professionalAnthony Mushrow22-Apr-08 13:37 
GeneralRe: Ok, im confused. Pin
dennycrane22-Apr-08 14:36
dennycrane22-Apr-08 14:36 
QuestionHow i can block the incomming network traffic using C# .NET Pin
Tahir Abbasi22-Apr-08 8:16
Tahir Abbasi22-Apr-08 8:16 
AnswerRepost ignore Pin
led mike22-Apr-08 8:39
led mike22-Apr-08 8:39 
AnswerRe: How i can block the incomming network traffic using C# .NET Pin
Pete O'Hanlon22-Apr-08 8:49
mvePete O'Hanlon22-Apr-08 8:49 
GeneralRe: How i can block the incomming network traffic using C# .NET Pin
Paul Conrad22-Apr-08 15:28
professionalPaul Conrad22-Apr-08 15:28 

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.