简体   繁体   中英

How do I create a Default Constructor using this C# code?

I'm trying to make a Default Constructor using this code. This is the original without the constructors, can someone please help?:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Chapter_2_Test
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }



    private void Order_Click(object sender, EventArgs e)
    {

    string cakeFlavor, frostingFlavor;
    int size; //This declasres an integer that represents size
    cakeFlavor = Cake.Text;            frostingFlavor = Frosting.Text;
    size = Convert.ToInt32(Size.Text);

    Display.Text = "Cake Flavor: " + cakeFlavor + Environment.NewLine + "Frosting Flavor: " + frostingFlavor + Environment.NewLine + "Cake Size: " + size + " Inches" + Environment.NewLine + "Thank you for shopping" + enter code hereEnvironment.NewLine + "at The Token Bakery!";
        //This Displays all the info that the user input

    }

}

}

It would be much appreciated. Thank you!

A piece of cake for me doing your homework?

class Cake
{
#region Fields
private string _cakeFlavor;
private string _frostingFlavor;
#endregion

#region Properties
public string CakeFlavor
{
    get { return _cakeFlavor; }
    set { _cakeFlavor = value; }
}

public string FrostingFlavor
{
    get { return _frostingFlavor; }
    set { _frostingFlavor = value; }
}
#endregion

#region Constructors
public Cake() : this("Cake flavor not provided.", "Frosting flavor not provided.")
{
}
public Cake(string cakeFlavor, string frostingFlavor)
{
    this._cakeFlavor = cakeFlavour;
    this._frostingFlavor = frostingFlavor;
}
#endregion

#region Methods
public void PrintCakeFlavors()
{
    Console.WriteLine("Cake Flavor: {0}\nFrosting Flavor: {1}", this._cakeFlavor, this._frostingFlavor);
}
#endregion
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM