在C#中,可以使用以下几种方式定义和初始化变量:
int myNumber = 10;
string myName = "John Doe";
bool isAvailable = true;
int myNumber;
myNumber = 10;
string myName;
myName = "John Doe";
bool isAvailable;
isAvailable = true;
var myNumber = 10;
var myName = "John Doe";
var isAvailable = true;
Person person = new Person
{
Name = "John Doe",
Age = 30,
IsAvailable = true
};
List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
Dictionary<string, bool> availability = new Dictionary<string, bool>
{
{ "John Doe", true },
{ "Jane Smith", false }
};