C# vscode practice - inheritance

in #kr-it7 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.20
TRX 0.25
JST 0.037
BTC 97089.33
ETH 3426.60
USDT 1.00
SBD 2.95