2011-01-27 172 views
-1

我有下面的代碼。聲明對象C#

於是我就用

if (myObject !=null) 

....但是這似乎並沒有工作,因爲它仍然在if語句執行代碼時myObject的值= NULL

 if (lawyerResponsibleUserField != null 
       && lawyerResponsibleUserField.Id != null) 
      { 
       // this effectively assigns Convert.ToString(null) 
       objLawyerResponsibileValue = Convert.ToString(workflowProperties != null 
        ? workflowProperties.Item[lawyerResponsibleUserField.Id] 
         : null); 
      } 
     if (objLawyerResponsibileValue != null) 
     { 
      lawyerResponsibleFieldValue = (SPFieldUserValue)objLawyerResponsibileValue; 
     } 
+1

你能告訴我們一些更全面的代碼? – Crisfole 2011-01-27 14:25:16

回答

1

試試這個

object myObject = null; 

    if(myObject != null) 
    { 
    // your code 
    } 
3

範 -

此賦值語句 -

object myObject = new Object(); 

...使其不爲空。 =)如果你要寫,它只會是空的:

object myObject = null; 

這裏的目標是什麼?

1

嘗試這些,

static void Main(string[] args) 
    { 
     object myObject = new Object(); 
     if (myObject == null) 
     { 
      Console.WriteLine("My Object is null"); 
     } 
     else 
     { 
      Console.WriteLine("My Object is NOT null"); 
     } 
    } 

寫入My Object is NOT null

static void Main(string[] args) 
    { 
     object myObject = null; 
     if (myObject == null) 
     { 
      Console.WriteLine("myObject is null"); 
     } 
     else 
     { 
      Console.WriteLine("My Object is NOT null"); 
     } 
    } 

寫入My Object is null