体验C#——关于一些循环语句
2014-12-02 10:15
323 查看
简单写了个C#关于循环语句测试的程序:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace XunhuanTest { //for语句 class ForStatement { public void forTest() { //打印直角三角形 for (int i = 0; i < 10; i++) { for (int j = 0; j < i; j++) { Console.Write("*"); } Console.WriteLine(); } //Console.ReadKey(); } } //while语句 class WhileStatement { //打印直角三角形 public void whileTest() { int i = 0; while (i < 10) { int j = 0; while (j < i) { Console.Write("*"); j++; } Console.WriteLine(); i++; } } //do-while和while的区别 public void dowhile_Or_while() { int i = 16; //do_while do { Console.WriteLine("dowhile 的输出结果:{0}",i); }while(i<15); //while while(i<15) { Console.WriteLine("while 的输出结果:{0}",i); } } } //foreach语句 class ForeachStatement { public void foreachTest() { string[] str = { "sdfd", "wefe" }; foreach (string i in str) { Console.WriteLine(i); } } } class Program { static void Main(string[] args) { //实例化一个for测试类 Console.WriteLine("测试for语句"); ForStatement forStatement = new ForStatement(); forStatement.forTest(); //实例化一个foreach测试类 Console.WriteLine("测试foreach语句"); ForeachStatement foreachStatement = new ForeachStatement(); foreachStatement.foreachTest(); //实例化一个while测试类 Console.WriteLine("测试while语句"); WhileStatement whileStatement = new WhileStatement(); whileStatement.whileTest(); whileStatement.dowhile_Or_while();//看while和do-while的区别 Console.ReadKey(); } } }
相关文章推荐
- 体验C#——关于循环语句的一些有趣题目的实现
- 关于C#执行多个SQL语句的一些操作——Note on Dec. 19th
- linux 中关于循环难得一些语句总结
- 关于循环语句的一些问题
- 关于C++的一些细节[四:循环,分支语句,关系表达式,关系运算符]
- C# 中的一些 基本语句,循环的格式.2
- 关于循环语句打印形状的一些思考
- 关于goto语句能不能从复杂的嵌套循环判断中跳出去的问题讨论
- 关于C#中用access做数据库,使用like语句的问题
- C#循环控制语句
- C#中国身份证验证 特别收集一些关于身份证验证的算法C#版
- 关于C++和C#的自定义数据类型转换的一些思考
- 关于goto语句能不能从复杂的嵌套循环判断中跳出去的问题讨论
- 关于一些C#的零碎资料--转载
- 关于goto语句能不能从复杂的嵌套循环判断中跳出去的问题讨论
- 关于goto语句能不能从复杂的嵌套循环判断中跳出去的问题讨论
- 关于goto语句能不能从复杂的嵌套循环判断中跳出去的问题讨论
- c#中关于字符串的一些函数.txt
- 关于goto语句能不能从复杂的嵌套循环判断中跳出去的问题讨论
- C#访问Xml 关于Foreach 和For循环