Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why a string comes back as null
Message
De
02/12/2008 19:40:14
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Why a string comes back as null
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Application:
Desktop
Divers
Thread ID:
01365266
Message ID:
01365266
Vues:
56
Hi All,

I have a method that returns a string if there is no file in a directory. I have stepped through this and watched this line get set to an empty string but when it comes back to the calling line of code, it is null. I am missing something and wonder if it is the way I did the while statement. Any ideas appreciated.
Thanks for the help
Tim

When the return from PopQueue is set to "" then in my while statement the value of fileName is null. Why would this be?
while ((fileName = this.PopQueue(path, filter)) != "" && llSuccess)
{
    // Do all my stuff here, process each file returned until no more files are returned.
}


private string PopQueue(string path, string filter)
{
    try
    {
        DirectoryInfo directory = new DirectoryInfo(path);
        FileInfo[] files = directory.GetFiles(filter);
        this.FilesInQueue = files.Length;

        foreach (FileInfo file in files)
        {
            // Verify this file isn't in the deleteList already
            if (deleteFileList.Contains(file.Name) == false)
            {
                return file.Name;
            }
            else
            {
                this.DeleteDataFile(path, file.Name);
            }
        }
    }
    catch (DirectoryNotFoundException)
    {
        // Need to try to recover the directory & or re-create it.
    }
    catch (Exception ex)
    {
        EventLogger.LogException(ex);
    }
    // When the directory is empty, return an empty string.		
    return "";
}
Timothy Bryan
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform