Q:

What is the proper way to return two char arrays as a single string?

I have a public property in a static class which I want to use as a means of validating the user's input against illegal file and path names.
At present I have this:
private static string invalidFileNames = new string(Path.GetInvalidFileNameChars());

private static string invalidPathNames = new string(Path.GetInvalidPathChars());

private static string invalidUserInput = (invalidFileNames + invalidPathNames); 

public static string InvalidUserInput
{

    get { return invalidUserInput; }

}

Based on Microsoft's documentation here I am expecting to get back "<>|"<>| But all I am getting is the first "<>|.
Can anyone shed some light as to what is happening here? How do I ensure that I get both strings returned?   

A:

You could just make it a single string
using System.Linq;

public static string InvalidUserInput
{
    get 
    {
        return new string(Path.GetInvalidFileNameChars()
                  .Concat(Path.GetInvalidPathChars())
                  .Distinct()
                  .ToArray());
    }
}

You wont see them all in a TextBox because of the terminator type chars in InvalidUserInput in your case its the \0(null teminator) that its stopping the display.
if you want to display just the ones that make sense to the user you can strip out the ones that cause the issue using Char.IsControl
Here is a static class to wrap it all up
public static class StringExtentions
{
    private static string _invalidUserInput = string.Empty;
    private static string _PrinatbleInvalidUserInput = string.Empty;

    public static string InvalidUserInput
    {
        get
        {
            if (_invalidUserInput == string.Empty)
            {
                _invalidUserInput = new string(Path.GetInvalidFileNameChars()
                      .Concat(Path.GetInvalidPathChars())
                      .Distinct()
                      .ToArray());
            }
            return _invalidUserInput;
        }
    }

    public static string GetPrinatbleInvalidUserInput
    {
        get
        {
            if (_PrinatbleInvalidUserInput == string.Empty)
            {
                _PrinatbleInvalidUserInput = new string(InvalidUserInput.Where(x => !char.IsControl(x)).ToArray());
            }
            return _PrinatbleInvalidUserInput;
        }
    }

    public static bool IsValidUserInput(this string str)
    {
        return !str.Any(c => InvalidUserInput.Contains(c));
    }
}

usage:
public MainWindow()
{
    InitializeComponent();
    string myString = "C:\\InvalidPath<";

    if (!myString.IsValidUserInput())
    {
        MessageBox.Show(string.Format("String cannot contain {0}", StringExtentions.GetPrinatbleInvalidUserInput));
    }
}

