c# - Constructor with unknown argument -
i have started programming in c#, after spending of life in php.
in php this:
class user { public __construct($userid) { // stuff } } class employee extends user { public __construct($employeeid) { // userid connected $employeeid $userid = hypothetical_get_user_id_func($employeeid); parent::__construct($userid); } } but, in c# don't seem have possibility, since seems must know $userid before enters first constructor.
public class user { public user(int userid) { // stuff } } public class employee : user { public employee(int employeeid) : base(***) // don't know value yet? { // find user id, , pass // user class constructor. } } is there way achieve trying here in c#?
basically passing value constructor of main object, in own body figures out value pass base class.
you can call static method in constructor. non standard though.
public class user { public user(int userid) { // stuff } } public class employee : user { public employee(int employeeid) : base(getuserid(employeeid)) { } public static int getuserid(int employeeid) { return employeeid - 5; } }
Comments
Post a Comment