Monday, May 13, 2024

How to set properties of class - Modal -Business Object

public class Student

        {

            public String Zone { get; set; }

            public String Branch { get; set; }

               }


 Student s = new Student();

        string property = "age";

        var age = s.GetType().GetProperty(property);

        age.SetValue(s,25);


PropertyInfo[] myPropertyInfo;

// Get the properties of 'Type' class object.

myPropertyInfo = Type.GetType("System.Type").GetProperties();

Console.WriteLine("Properties of System.Type are:");

for (int i = 0; i < myPropertyInfo.Length; i++)

{

    Console.WriteLine(myPropertyInfo[i].ToString());

}


ref:- https://stackoverflow.com/questions/58933272/how-to-access-class-properties-using-variable-name-in-net-core

https://stackoverflow.com/questions/8008389/how-to-convert-datatable-to-class-object

https://stackoverflow.com/questions/18746064/using-reflection-to-create-a-datatable-from-a-class

https://learn.microsoft.com/en-us/dotnet/api/system.type.getproperties?view=net-8.0

https://stackoverflow.com/questions/18746064/using-reflection-to-create-a-datatable-from-a-class

https://stackoverflow.com/questions/1346132/how-do-i-extract-data-from-a-datatable

No comments:

Post a Comment