数组
using System;
using System.Collections;
namespace ConsoleApp1
{
class Programs
{
static void Main(string[] args)
{
int[] arr1 = { 1, 2, 3, 4};
int[] arr2 = new int[4];
foreach (int item in arr1) {
Console.WriteLine(item);
}
for (int i = 0; i < arr2.Length; i++) {
Console.WriteLine(arr2[i]);
}
ArrayList arrayList = new ArrayList() {1,2,3,4};
arrayList.Add(65);
arrayList.Insert(0,10);
Console.WriteLine(arrayList.Count);
Console.WriteLine(arrayList.Capacity);
}
}
}
字符串
using System;
using System.Collections;
namespace ConsoleApp1
{
class Programs
{
static void Main(string[] args)
{
string str1 = "sasa";
str1 = "hello";
foreach (char c in str1) {
Console.Write(c);
}
Console.WriteLine();
for (int i = 0; i < str1.Length; i++) {
Console.Write(str1[i]);
}
str1 = str1.ToUpper();
str1 = str1.ToLower();
str1 = str1.Substring(0, 1);
str1 = str1.Trim();
str1 = str1.TrimStart();
str1 = str1.TrimEnd();
}
}
}
可乐问题
using System;
using System.Collections;
namespace ConsoleApp1
{
class Programs
{
static void Main(string[] args)
{
int bottle = Convert.ToInt32(Console.ReadLine());
int drinkNum = bottle;
int emptyNum = bottle;
while (emptyNum > 2) {
drinkNum += emptyNum / 3;
emptyNum = emptyNum / 3 + emptyNum % 3;
}
Console.WriteLine("剩下{0}空瓶,喝了{1}",emptyNum,drinkNum);
}
}
}