Condition in a list

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);
 }
    
asked by anonymous 12.12.2017 / 21:13

1 answer

1

.ToArray has 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);
}
    
12.12.2017 / 21:18