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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -