C# vscode practice - inheritance

in #kr-it6 years ago

For the Inheritance, We have to be careful to use variables.

We have upper class of Address
@ street
@ city
@ zip

and InternationalAddress inherited Address
@ country

Then, we can not put country to address directly

I wanted to put @address.Country = "Korea";
But it returns the compile error.

Then i changed to @interaddress.Country = "Korea";
It has succeeded.

Here is the code

/////////////////////////

public class Address
{
public string StreetAddress;
public string City;
public string State;
public string Zip;

    public override string ToString()
    {
        return string.Format("{0}" + Environment.NewLine +
            "{1}, {2} {3}",
            StreetAddress, City, State, Zip);
    }
} 

public class InternationalAddress : Address
{
    public string Country;

    public override string ToString()
    {
        return base.ToString() + Environment.NewLine + Country;
    }
}

//////////////////////////////

Coin Marketplace

STEEM 0.16
TRX 0.15
JST 0.028
BTC 56162.63
ETH 2368.26
USDT 1.00
SBD 2.31