c# - Using a variable from a different class and method into another class and method -
this main class person
public class person { public void setage(int n) { n = 20; } static void main(string[] args) { } }
and want access n variabe in inherited class student
class student : person { public void gotoclasses() { console.writeline("i going class"); } public void showage() { console.writeline("my age {0}",n); } }
i tried using person.n or setage(20) or setage(n) , won't work !
public class person { public int age {get; set;} }
above represents basic object.
use case:
person person = new person(); person.age = 25;
other object additions:
public class person { public date birthdate {get; set;} public int age { { return (datetime.now.year - birthdate.year); } } //read }
Comments
Post a Comment