c# - What would cause a property get on an interface to fail? -
i have interface property, , class implements interface. cast instance of class interface, attempt read property , doesn't retrieve value. can see why?
interface:
public interface ifoo { int objectid { get; } }
class:
public class bar : ifoo { public int objectid { get; set; } }
usage:
... bar mybar = new bar() { objectid = 5 }; ifoo myfoo = mybar ifoo; int myid = myfoo.objectid; //value of myfoo.objectid 5 in watch, myid remains @ 0 after statement ...
this oversimplified, i'm doing. why can see value of myfoo.objectid in watch window, assignment myid fails (value 0 before , after assignment)?
you might have manipulated data on watch through manual intervention or statement changed value.
i did quick test on code in console application , value of myid 5.
class program { static void main(string[] args) { bar mybar = new bar() { objectid = 5 }; ifoo myfoo = mybar ifoo; int myid = myfoo.objectid; console.writeline(myid); // 5 console.readline(); } } interface ifoo { int objectid { get; } } class bar : ifoo { public int objectid { get; set; } }
Comments
Post a Comment