我有一個以通用方式從構造函數中獲取值的問題。我如何在構造函數中獲取使用的參數的值(C#)
namespace myTestNamespace
{
Public Class myTestClass()
{
Public myTestClass(int myInt,bool myBool, double myDouble)
{
//do/set something
}
Public myTestClass(int myInt,bool myBool)
{
//do/set something
}
}
}
Using (what you need);
Using myTestNamespace;
namespace MyIWannaLookForTheParametersName
{
Public Class MyLookUpClass()
{
Public void DoSomething()
{
List<object> myList = new List<object>();
myTestClass _ myTestClass = new myTestClass(1,true,2.5);
object mySaveObject = myTestClass;
mylist.Add(mySaveObject);
//how do I get the info from the right constructor
//(I used the one with 3 parameters_
//what was the value of myInt, myBool and myDouble
//how can I make it generic enough, so it will work with other classes with
// different constructors ass well?
}
}
}
這不是完全清楚你想要做什麼,說實話。不應該把所有的信息都放在對象本身中嗎?你爲什麼關心它是如何構建的? –
你能舉一個你想要做什麼的例子嗎? (你有什麼和你想要什麼...) –
這應該做什麼? –