我有想接受一個對象作爲參數,並使用其屬性爲進一步使用功能,但是當我嘗試訪問對象的屬性也將其標記爲紅色(不能解析符號。 ..) 我試圖添加幾個參考,但它沒有幫助。C#類庫,訪問對象的屬性
public bool InsertStudent(object student)
{
var db = DAL.Services.SqlServicesPool.HackService;
using (var connection = db.StartConnection())
{
var sqlParam = new SqlParameter[]
{
new SqlParameter("@Name", student.Name),
new SqlParameter("@Lname", student.Lname),
new SqlParameter("@Phone", student.Phone),
new SqlParameter("@Email", student.Email),
new SqlParameter("@Img", student.Img),
new SqlParameter("@CityId", student.CityId)
};
var result = db.Exec(connection, "spInsertNewStudent", sqlParam);
db.StopConnection(connection);
return result;
};
}
你要投類型的對象,以你的學生類型像這樣(的MyType)學生 – Serghei
[C#投對象其數據類型obj.GetType()]的可能的複製(http://stackoverflow.com/questions/31821151/C鋒利投對象到其-數據類型-OBJ-將gettype) – jomsk1e
是的,謝謝,ü所有睜開眼睛的原因,是我太固定丟失的引用後,沒有必要下投我要是,我是一個初學者,我的問題是明確的和乾淨的 – tomersss2