I understand that what I'm trying to do is a bit of a hack, but it's interesting nonetheless.
I'm in a situation where it is quite possible that an array might not have as many items as I expect.
Here's the concept:
namespace TESTAPP { class Program { static void Main(string[] args) { string derp = "foooooo"; //The split is important, you might not have the character there to split by Writer(derp.Split('x')[0] ?? "."); Writer(derp.Split('x')[1] ?? "."); } private static void Writer(string writeme) { Console.WriteLine(writeme ?? ".."); } } }
VulpesPosted Jul 2, 2013, 9:25 AM
Notice that there's no point using the expression derp.Split('x')[i] as the left hand operand of the null-coalescing operator ??.
That's because it can never be null as it always returns a char or throws an exception:
Kunal VaishyaPosted Jul 2, 2013, 8:29 AM