how to get array values size

Last post 07-03-2009 4:20 AM by Paul Linton. 1 replies.

Sort Posts:

  • how to get array values size

    07-03-2009, 1:27 AM

    Hello friends,
    I done a small program which i pasted below iam getting error in this line if(fail.Length =3). I dono how to get the array values size not length.So please me....
    string[] a=new string[5];
     By using Length method we can get length ie 6 as a output...But if i stored three string values how to get that value number...

    Please help me out.....

    <% 
    String Result="hello dude nvo what is ur problem nvo match today is it vow nvo match for its gud ya k then nvo entries";
    int[] Resultt = new int[6];
    string[] pass =new string[6];
    string[] fail =new string[6];
    String a = "available";
    String b="unavailable";

    string[] datas = new string[]
            {
                "no",
                "no match",
                "no match for",
                "no entries",           
            };
    for(int i = 0; i <= 3; i++)
    {
    Resultt[i] = Result.IndexOf(datas[i]);
    }
    for (int i = 0; i <= 3; i++)
    {
        if (Resultt[i] != -1)
        {
            //Response.Write("available");
      
      for(int j=0; j<=3; j++)
      {
      pass[j] = a;
      }
      
        }
        else
        {
            //Response.Write("unavailable");
      
      for(int k=0; k<=3; k++)
      {
      fail[k] = b;
      }
        }
     if(fail.GetLength =3)
     //if(fail.Length =3)
     //if(sizeof(fail) =3)
     {
     Response.Write("unavailable");
     }
     else
     {
     Response.Write("available");
     }
    }
    %>

  • Re: how to get array values size

    07-03-2009, 4:20 AM
    Answer
    • Contributor
      4,478 point Contributor
    • Paul Linton
    • Member since 04-29-2008, 11:16 PM
    • Posts 789

     I'm not quite sure what you are trying to do because the length of fail is 6 (you have set that when you assigned the new string[6] in the declaration of fail). 

    But, when you compare you need to use == and not =.  A single = is for assignment.  A double == is for comparison.  So fail.Length==3 is false but fail.Length==6 is true.

    Let us know what you are really trying to do if you need more help.

    Got a c# problem? Try .NET Book Zero from Charles Petzold, it's a free pdf.
Page 1 of 1 (2 items)