[Fork] Fullname example

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public static void Main()
	{
		var p = new Person { FirstName = "Rob", LastName = "Janssen" };
		
		Console.WriteLine(p.FullName);
	}
}

public class Person {
	public string FirstName {get;set;}
	public string LastName {get;set;}
	public string Infix {get;set;}
	
	public string FullName {
		get { return FirstName.SafeConcat(" ", Infix).SafeConcat(" ", LastName); }
	}
	
}

public static class MyStringExtensions {
	
	public static string SafeConcat(this string self, string separator, string value) {
		if (self == null)
			return value ?? string.Empty;
		return self + (value == null ? string.Empty : separator + value);
	}
	
}
;