2

hi I get values from a textbox and i split it to a array.. Then i got the max value it is not saying real value;

here code is used

 string[] cwatchers = textBox4.Text.Split('\n');
        string[] sss = textBox1.Text.Split('\n');
        string[] emails = textBox2.Text.Split('\n');

        var sb = new StringBuilder();
        sb.AppendLine("VERSION BUILD=8820413 RECORDER=FX");
        sb.AppendLine("SET !ERRORIGNORE YES");
        sb.AppendLine("SET !TIMEOUT_TAG 3");
        sb.AppendLine("SET !TIMEOUT_STEP 3");
        sb.AppendLine("SET !TIMEOUT_PAGE 7");
        sb.AppendLine("SET !REPLAYSPEED FAST");

        for (int i = 0; i < Convert.ToInt64(cwatchers.Max()); i++)
        {
            sb.AppendLine("TAB T=1").AppendLine("CLEAR");
            sb.AppendLine("URL GOTO=https://signin.ebay.com/ws/eBayISAPI.dll?SignIn&lgout=");
            sb.AppendLine("WAIT SECONDS=1");
            sb.AppendLine("TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:SIGNINFORM ATTR=ID:SUBMIT");
            sb.AppendLine("SET !ENCRYPTION NO");
            sb.AppendLine("TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:SIGNINFORM ATTR=ID:PASS CONTENT=Maths7524");
            sb.Append("TAG POS=1 TYPE=INPUT:TEXT FORM=ID:SIGNINFORM ATTR=ID:USERID CONTENT=").AppendLine(emails[i]);
            sb.AppendLine("TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:SignInForm ATTR=ID:sgnBt");
            sb.AppendLine("WAIT SECONDS=7");
            foreach (string item in sss)
            {
                sb.Append("URL GOTO=www.ebay.com/itm/").AppendLine(item);
                sb.AppendLine("WAIT SECONDS=1").AppendLine("TAG POS=1 TYPE=SPAN ATTR=ID:watchLabel");
                sb.AppendLine("TAG POS=1 TYPE=A ATTR=TXT:Watch").AppendLine("WAIT SECONDS=1").AppendLine();
            }
        }

        label5.Text = cwatchers.Max();

here i use detaisl

label5 says max value is 70

as we can see max value is 180.. could anybody tell me why this is getting false ?

3
  • are you trying to get the amount of elements in the array ? Commented Dec 20, 2017 at 10:20
  • yes i got to the array using split keyword Commented Dec 20, 2017 at 10:22
  • Most of the code is not related to the problem. Please provide a minimal reproducible example next time Commented Dec 26, 2017 at 20:58

3 Answers 3

7

You need first to cast the elements to int, because now they are strings. Try something like this:

label5.Text = cwatchers.Max(x=>int.Parse(x));

This parses all the elements to int and then finds the max value. Notice that it will throw an exception if any of the elements can't be parsed to int.

Sign up to request clarification or add additional context in comments.

Comments

6

Literally 70 is greater 180, as both are strings. Having said this what happens is that every character in your string is compared to the matching character in the other string at the same position. As "7" surely is greater "1", "70" also is greater then "180".

To avoid a lexical compairsion use a numerical instead, you have to treat your data as numbers:

var max = label5.Select(x => Convert.ToInt32(x)).Max();

Comments

3

This should do the job:

label5.Text = cwatchers.Select(Int32.Parse).Max().ToString();

You need to convert your String variables to Int32 before performing a maximum detection. Otherwise the comparison will be performed on String, producing a completely different result.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.