#767 – A struct Is Implicitly Sealed

Every struct in C#, whether it is user-defined or defined in the .NET Framework, is sealed–meaning that you can’t inherit from it.  A struct is sealed because it is a value type and all value types are sealed.

A struct can implement an interface, so it’s possible to see another type name following a colon, after the name of the struct.

In the example below, we get a compile-time error when we try to define a new struct that inherits from the one defined above.

    public struct PersonName
        public PersonName(string first, string last)
            First = first;
            Last = last;

        public string First;
        public string Last;

    // Error at compile time: Type 'PersonName' in interface list is not an interface
    public struct AngryPersonName : PersonName
        public string AngryNickname;

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

One Response to #767 – A struct Is Implicitly Sealed

  1. Pingback: Dew Drop – January 28, 2013 (#1,488) | Alvin Ashcraft's Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: