Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6078347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:49:24+00:00 2026-05-23T10:49:24+00:00

I want to avoid that the function GetListCsvFiles () returns a null, when there

  • 0

I want to avoid that the function GetListCsvFiles () returns a null, when there is no file in the directory.

I can add a test, but I want to avoid if possible.

using System;
using NLog;

namespace ConsoleApplication1
{
    class Program
    {

        private static Logger report = LogManager.GetLogger("EventReport");

        static void Main(string[] args)
        {
            report.Info("Start Program");
            EveryQuotesDB everyQuotesDB = new EveryQuotesDB();
            //string[] csvFiles = everyQuotesDB.GetListCsvFiles(@"C:\DirectoryCsvFiles");
            string[] csvFiles = everyQuotesDB.GetListCsvFiles(@"C:\DirectoryEmpty");

                foreach (string file in csvFiles)
                {
                    report.Info(file);
                };

            report.Info("End Program");
            Console.ReadLine();
        }

    }
}



using System.IO;
using NLog;

namespace ConsoleApplication1
{
   class EveryQuotesDB
    {
        private static Logger report = LogManager.GetLogger("EventReport");

        public string[] GetListCsvFiles(string directoryCsvFiles)
        {
            string[] csvFiles = null;

            try
            {
                csvFiles = Directory.GetFiles(directoryCsvFiles, "*.csv");
            }
            catch (DirectoryNotFoundException)
            {
                report.Fatal("Directory Not Found : " + directoryCsvFiles);
            }

            return csvFiles;
        }


    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:49:24+00:00Added an answer on May 23, 2026 at 10:49 am

    Replace this line:

    string[] csvFiles = null;
    

    with this:

    string[] csvFiles = new string[0];
    

    That will make the default value an empty string array instead of null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to generate some passwords, I want to avoid characters that can be
I have a function that causes an exception in the designer. Can I avoid
I want to do some quick inserts but avoid duplicates into a Table. For
I want to write a function that allows users to match data based on
Is there a built-in function that would convert a color by name into its
I want to create a function that takes an integer as it's parameter and
I want to have a function that evaluates 2 bool vars (like a truth
I have a function that does xml parsing. I want to make the function
Is there some way I can execute code in the base function for all
my proble is to avoid that users upload some malicious file on my web-server.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.