Condition on a list

Asked

Viewed 25 times

0

I have a program that inserts information into a CSV file. And I wanted to check if there is data in the variable if it does not show a message that there is no data entered in the file.

 var csv = listForRegister.Select(l => String.Join(";", 
                                                   l.DriverName.ToString(), 
                                                   l.NationalId.ToString(),
                                                   l.InitialTime,
                                                   l.EndTime,
                                                   l.Distance.ToString() 
                                                   + " Km")).ToArray();


 if ( csv == null )
 {
     string display = "Não ha registro nesta data.";
     ClientScript.RegisterStartupScript(this.GetType(), 
                                        "yourMessage", 
                                        "alert('" + display + "');", true);
     Response.Redirect(Page.Request.Path);
 }
  • try to put your if the following way if (csv == null || !csv.Any())

1 answer

1


the .ToArray owns the property Array.Length, I think this should work

if ( csv.Length == 0 )
{
    string display = "Não ha registro nesta data.";
    ClientScript.RegisterStartupScript(this.GetType(), "yourMessage", "alert('" + display + "');", true);
    Response.Redirect(Page.Request.Path);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.