Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is a C# class with no implementation valid? [closed]

Tags:

c#

.net

class

I've stumbed across this class in an existing code base:

[Serializable]
public class PillowFight
{
    public PillowFight(object providedObject);

    public object providedObject { get; }
    public Dictionary<string, PillowData> Properties { get; }

    public PillowData GetPillowByName(string pillowName);
    public void SetPillowValue(string pillowName, object value);
}

I would not have expected this to compile because of the missing implementations on the constructor, GetPillowByName and SetPillowValue since it's not abstract or an interface. This is valid? Why would one do this and what's the advantage?

like image 630
sonicblis Avatar asked Dec 06 '22 01:12

sonicblis


1 Answers

No, it is not valid. Probably you have seen this when using the 'go to definition (F12)' function in Visual Studio. If the source is in another assembly, it will only show the outline, not the actual code.

See the corresponding dotnetfiddle (which doesn't compile).

Error:

PillowFight.PillowFight(object)' must declare a body because it is not marked abstract, extern, or partial

like image 107
Patrick Hofman Avatar answered Dec 10 '22 12:12

Patrick Hofman