C#入门

c#入门

int a = 1
Console.WriteLine($"a is {a}")
int a = 5;
int b = 3;
if (a + b > 10)
{
    Console.WriteLine("The answer is greater than 10");
}
else
{
    Console.WriteLine("The answer is not greater than 10");
}
for (int index = 0; index < 10; index++)
{
    Console.WriteLine($"Hello World! The index is {index}");
}

var names = new List<string> { "<name>", "Ana", "Felipe" };
foreach (var name in names)
{
    Console.WriteLine($"Hello {name.ToUpper()}!");
}

var names = new List<string> { "Tom", "Ana", "Felipe" };

var names = new List<string> { "Tom", "Ana", "Felipe" };
names.Add("Bob")
names.Remove("Bob")

如果不存在,则返回-1

var index = names.IndexOf("Felipe");

Sort 方法按正常顺序(如果是字符串则按字母顺序)对列表中的所有项进行排序。 在程序底部添加以下代码: names.Sort();