0

有没有办法在 C# 中做你可以做的事情(伪代码):

class User
{
     $FirstName = { get; set; }
     $LastName = { get; set; }
}

$array = array(
    new User { FirstName: "John", LastName: "Wibbly" },
    new User { FirstName: "Yank", LastName: "Anchor" }
)

还是我需要使用构造函数参数?

我只是问,因为我想知道 __Get 和 __Set 方法是否应该在这里做一些聪明的事情。

编辑::

所以如果我使用 set_state:

class User
{
     public $FirstName = { get; set; }
     public $LastName = { get; set; }

     public function __set_state( $param )
     {
          $obj = new User;
          $obj = $param[ 'FirstName' ];
          $obj = $param[ 'LastName' ];
          return $obj;
     }    
}

// 我现在如何做这部分:?

$array = array(
    new User { FirstName: "John", LastName: "Wibbly" },
    new User { FirstName: "Yank", LastName: "Anchor" }
)
4

0 回答 0