What causes exception in string.concat
        Posted  
        
            by 
                Budda
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Budda
        
        
        
        Published on 2011-01-03T16:45:00Z
        Indexed on 
            2011/01/03
            16:54 UTC
        
        
        Read the original article
        Hit count: 623
        
Here are few classes:
public class MyItem : ParamOut
{
    public string Code
    {
        get { return _quoteCode; }
    }
    public InnerItem[] Skus
    {
        get { return _skus; }
    }
    public PriceSummary Price
    {
        get { return _price; }
    }
    public override string ToString()
    {
        return string.Concat("Code=", Code, "; SKUs=[", Skus != null ? "{" + string.Join("},{", Array.ConvertAll(Skus, item => item.ToString())) + "}" : "", "]"
            , "; Price={", Price.ToString(), "}", base.ToString()
            );
    }
    ...
}
public abstract class ParamOut
{
    public override string ToString()
    {
        return null;
    }
    public string ErrorMessage { get; set; }
}
Here is calling functionality:
{
    MyItem item = new MyItem{ ErrorMessage = "Bla-bla-bla" };
    string text = item.ToString();
}
I am getting NullReference exception inside of 'ToString()' method (each property of item variable is null).
Question:
Q1. what overload of string.Concat will be called in this case? I have 9 parameters, so I guess one of the following:
public static string Concat(params Object[] args)
or
public static string Concat(params string[] values)
But which of them?
Q2. Why exception is generated? Shouldn't 'null' be converted into something like 'null' or "" (empty string)?
Thanks a lot!
© Stack Overflow or respective owner