Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
Declare a new object instance from an exist object instance
Jim Feng
Oct 25 2017 12:10 PM
147
Reply
I try to code a common method to fill in an class object list with datatable as following:
public static List FillDataTable(object obj, DataTable dt)
{
List objList = new List();
object o = new object(); //how to declare this instance based on the object obj???
foreach (DataRow dr in dt.Rows)
{
//code to fill datarow to the object o
objList.Add(o);
}
return objList;
}
Call this method as followiing:
List lstObj = new List();
lstObj = FillDataTable(((object)new myClass()), dt).OfType().ToList();
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
OLEDB Connection
How to edit data in search result in c#