如何使用C#获取传入对象的值

时间:2014-04-03 11:10:09

标签: c#-4.0

我有以下代码

     public void ShowForm(String EName, String phoneNumber, String dnis, String mode, String callid)
    {

        objCallParams.EventName = EName;
        objCallParams.ANI = phoneNumber;
        objCallParams.DNIS = dnis;
        objCallParams.Mode = mode;
        objCallParams.CallId = callid;

        UIThreadContext.Post(InComing_Callback, (object)objCallParams);
    }
    private void InComing_Callback(object objCallParams)
    {
      /*want to access phone number i.e.objCallParams.ANI*/
    }

如何在InComing_Callback(object objCallParams)方法中访问phoneNumber?

1 个答案:

答案 0 :(得分:0)

如果您知道对象的类型,可以使用casting

private void InComing_Callback(object objCallParams)
{
    // If you know that objCallParams will always be of the type FormParameters:
    var params = (FormParameters)objCallParams;

    // if you are not so sure about that
    var notSoSureParams = objCallParams as FormParameters;
    if (notSoSureParams != null)
    {

    }
}