struct in a different assembly used without initialization

Viewed 56

The following C# program doesn't compile

    class Program
    {
        public struct MetaWorkspace
        {
            public string Name { get; set; }
            public string Id { get; set; }
        }

        static void Main(string[] args)
        {
            MetaWorkspace ws;
            ws.Id = "abc";
        }
    }

The compiler complains: error CS0165: Use of unassigned local variable 'ws'

The compiler is Microsoft (R) Visual C# Compiler version 3.10.0-4.21329.37 and the version of .NET Framework is 4.7.2

But, the same program compiles successfully when the MetaWorkspace struct definition is moved into a different assembly (DLL) and is included as a reference. How is this so? If this is not an error, am I still dealing with a fully defined MetaWorkspace object or have I tread into the undefined zone?

0 Answers
Related