Home >Backend Development >C#.Net Tutorial >How to implement interface in anonymous class in C#?
No, anonymous types cannot implement interfaces. We need to create your own type.
Anonymous types provide a convenient way to encapsulate a set of read-only types Properties are converted to a single object without first explicitly defining the type.
Type names are generated by the compiler and are not available in the source code grade. The type of each property is inferred by the compiler.
You can create anonymous types by using the new operator with an object Initialization program.
class Program{ public static void Main(){ var v = new { Amount = 108, Message = "Test" }; Console.WriteLine(v.Amount + v.Message); Console.ReadLine(); } }
108Test
The above is the detailed content of How to implement interface in anonymous class in C#?. For more information, please follow other related articles on the PHP Chinese website!