using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleWriteline
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Method 1:");
Console.WriteLine("The first app in Beginning C# Programming!");
Console.WriteLine("Method 2:");
string str1 ="The first app in Beginning C# Programming!";//定义一个字符串变量
Console.WriteLine(str1);
Console.WriteLine("Method 3:");
string[] str2 = { "The", "first", "app", "in", "Beginning", "C#", "Programming!" };//定义一个字符串数组,静态初始化
for (int j = 0; j < str2.Length; j++)//for循环
{
Console.Write(str2[j]+' ');//or (str2[j]+" ")
}
Console.WriteLine("\nMethod 4:");
string[] str3 = new string[] { "The", "first", "app", "in", "Beginning", "C#", "Programming!" };//定义一个字符串数组,动态初始化
foreach (string s in str3)//foreach循环
{
Console.Write("{0} ",s);
}
Console.WriteLine("\nMethod 5:");
char[] ch = new char[] { 'T', 'h', 'e', ' ', 'f', 'i', 'r', 's', 't', ' ', 'a', 'p', 'p', ' ', 'i', 'n', ' ', 'B', 'e', 'g', 'i', 'n', 'n', 'i', 'n', 'g', ' ', 'C', '#', ' ', 'P', 'r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g', '!',(char)0 };
int i = 0;
do//do-while循环
{
Console.Write("{0}",ch[i]);
i++;
} while (ch[i] != '\0');
}
}
}
实现同样的结果,哪种方法执行效率最高呢
还有执行效率更高的代码可以实现字符串的输出吗?
程序执行效率问题一直都是程序员不得不考虑的问题。
请问怎样判断程序执行效率的高低?怎样才能写出执行效率高的代码?大家都来给点意见吧。