Monday, January 4, 2021

how to get total number of public properties in a class c#

 class MyClass

{  
    public string A { get; set; }
    public string B { get; set; }
    public string C { get; set; }

    public MyClass()
    {
        int count = this.GetType().GetProperties().Count();
        // or
        count = typeof(MyClass).GetProperties().Count();
    }
}

No comments:

Post a Comment

ASP.NET Core

 Certainly! Here are 10 advanced .NET Core interview questions covering various topics: 1. **ASP.NET Core Middleware Pipeline**: Explain the...