一个结构可以像下面的代码一样在类内创建吗?什么是创建一个结构的正确方法是在类内创建有用的?和其他问题是,如果一个结构的属性必须声明与getter和setter像这样public int Strength {get;设置;}或以它在下面显示的代码中的方式是好的?一个结构体可以在类内部创建吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace createStructs
{
class Program
{
static void Main(string[] args)
{
}
struct Coffee
{
/*properties*/
public int Strength;
public string Bean;
public string CountryOfOrigin;
/*constructor*/
public Coffee(int strength, string bean, string countryOfOrigin)
{
this.Strength = strength;
this.Bean = bean;
this.CountryOfOrigin = countryOfOrigin;
}
}
}
你为什么不试试......? – metadings
既然你有代码,那你为什么不打F5看看它是否编译?如果是这样,那么你已经回答了你自己的问题。如果没有,你已经回答了你自己的问题:) – dman2306
@ dman2306单独编译使用'ctrl + shift + B' F5将运行应用程序:) –