write C# code for the following tech test prompt:
#Tax Rate Calculator

##Background

Every investor has a tax rate, which determines what part of their income they will need to pay as tax. For example, tax rate of 15% means that investor will pay 15$ tax on income of 100$.

In our system we need to know the tax rate for all investor when we process their business transactions. We'd like you to implement the following functionality:

###Given the investor, return their Tax Rate.

##Investor has the following properties:

Legal Type - individual, company, charity
Country of residence. String. If it has "New Zealand" in as its value, it means the investor is resident.
Tax Exempt - is the investor exempt from Tax
Tax Rate - the Tax Rate that is recorded against the investor
##There are the following business requirements:

###For Charity, the Tax Rate is defined as follows:

For a Charity who is a Resident, Tax Rate is 0 regardless of what their Tax Rate is set to
For a Charity that is a non-Resident, Tax Rate is 15%
###For Individual or a Company, the Tax Rate is defined as follows:

If they are resident and are Tax Exempt, then 0
If they are resident and non Tax Exempt, then its their Tax Rate
If their tax rate was not set, return default of 33%
If they are non-resident then Tax Rate is 15%
user
here's the c# code to implement the tax rate calculator according to the provided requirements:

```csharp
using system;

namespace taxratecalculator
{
    public enum legaltype
    {
        individual,
        company,
        charity
    }

    public class investor
    {
        public legaltype legaltype { get; set; }
        public string countryofresidence { get; set; }
        public bool taxexempt { get; set; }
        public double? taxrate { get; set; }
    }

    public class taxratecalculator
    {
        public double calculatetaxrate(investor investor)
        {
            bool resident = investor.countryofresidence.contains("new zealand");

            if (investor.legaltype == legaltype.charity)
            {
                return resident ? 0 : 0.15;
            }

            if (investor.legaltype == legaltype.individual || investor.legaltype == legaltype.company)
            {
                if (resident)
                {
                    if (investor.taxexempt)
                    {
                        return 0;
                    }
                    else
                    {
                        return investor.taxrate ?? 0.33;
                    }
                }
                else
                {
                    return 0.15;
                }
            }

            throw new invalidoperationexception("invalid legal type.");
        }
    }

    class program
    {
        static void main(string[] args)
        {
            taxratecalculator taxratecalculator = new taxratecalculator();

            investor investor1 = new investor
            {
                legaltype = legaltype.individual,
                countryofresidence = "new zealand",
                taxexempt = false,
                taxrate = 0.25
            };

            double taxrate1 = taxratecalculator.calculatetaxrate(investor1);
            console.writeline($"investor1 tax rate: {taxrate1 * 100}%");

            // add more test cases for different investors as required
        }
    }
}
```

the code defines a `legaltype` enumeration to represent the investor's legal type (individual, company, or charity). the `investor` class has properties for legal type, country of residence, tax exempt status, and tax rate. the `taxratecalculator` class has a `calculatetaxrate()` method that calculates the tax rate according to the provided requirements. the `program` class contains a `main` method that demonstrates the usage of the `taxratecalculator` class.
assistant
Here's the C# code to implement the tax rate calculator according to the provided requirements:

```csharp
using System;

namespace TaxRateCalculator
{
    public enum LegalType
    {
        Individual,
        Company,
        Charity
    }

    public class Investor
    {
        public LegalType LegalType { get; set; }
        public string CountryOfResidence { get; set; }
        public bool TaxExempt { get; set; }
        public double? TaxRate { get; set; }
    }

    public class TaxRateCalculator
    {
        public double CalculateTaxRate(Investor investor)
        {
            bool resident = investor.CountryOfResidence.Contains("New Zealand");

            if (investor.LegalType == LegalType.Charity)
            {
                return resident ? 0 : 0.15;
            }

            if (investor.LegalType == LegalType.Individual || investor.LegalType == LegalType.Company)
            {
                if (resident)
                {
                    if (investor.TaxExempt)
                    {
                        return 0;
                    }
                    else
                    {
                        return investor.TaxRate ?? 0.33;
                    }
                }
                else
                {
                    return 0.15;
                }
            }

            throw new InvalidOperationException("Invalid Legal Type.");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            TaxRateCalculator taxRateCalculator = new TaxRateCalculator();

            Investor investor1 = new Investor
            {
                LegalType = LegalType.Individual,
                CountryOfResidence = "New Zealand",
                TaxExempt = false,
                TaxRate = 0.25
            };

            double taxRate1 = taxRateCalculator.CalculateTaxRate(investor1);
            Console.WriteLine($"Investor1 Tax Rate: {taxRate1 * 100}%");

            // Add more test cases for different investors as required
        }
    }
}
```

The code defines a `LegalType` enumeration to represent the investor's legal type (individual, company, or charity). The `Investor` class has properties for legal type, country of residence, tax exempt status, and tax rate. The `TaxRateCalculator` class has a `CalculateTaxRate()` method that calculates the tax rate according to the provided requirements. The `Program` class contains a `Main` method that demonstrates the usage of the `TaxRateCalculator` class.
assistant