Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
namespace Test
{
public class Program
{
public static void Main()
{
var first = new Outer
{
Initialized = { Value = "will work" },
//NotInitialized = { Value = "NullReferenceException will be thrown" }
};
}
// Define other methods and classes here
class Outer
{
public Inner Initialized { get; set; }
public Inner NotInitialized { get; set; }
public Outer()
{
Initialized = new Inner();
}
}
class Inner
{
public string Value { get; set; }
}
}
}
@TheAmph

This comment has been minimized.

Copy link

@TheAmph TheAmph commented Feb 6, 2017

How about:

      var first = new Outer
        {
            Initialized = { Value = "will work" },
            NotInitialized = new Inner() { Value = "this works too" }
        };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.