简单基础操作,字符串操作,循环等
2016-07-24 23:02
399 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test
{
class Program
{
static void Main(string[] args)
{
int i = 1;
object o = i;//装箱
int j = (int)o;//拆箱
//Console.WriteLine(j);
//插入字符串
string str = "This is a girl.";
str = str.Insert(10, "buautiful ");
Console.WriteLine(str);
//填充字符PadLeft串
string str1 = "Hello World!";
string strleft = str1.PadLeft(15, '@');
string strright = str1.PadRight(15, '@');
Console.WriteLine(strleft + " " + strright);
Console.WriteLine("----------while");
int n = 1;
while (n <= 8)
{
Console.Write(n); n++;
}
Console.WriteLine("");
Console.WriteLine("----------do while");
int b = 1;
do
{
Console.Write(b); b++;
}
while (b <= 8);
Console.WriteLine("");
Console.WriteLine("----------数组");
//数组
int[] arr = new int[8]{1,2,3,4,5,6,7,8};
foreach (int item in arr)
{
Console.Write(item);
}
Console.WriteLine("");
Console.WriteLine("----------二维数组for遍历");
int[,] array = new int[,] { { 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 } };
for (int g = 0; g < 4; g++)//行的行数
{
for (int h = 0; h < 2; h++)//行的列数
{
Console.Write(array[g, h] + "\t");
}
Console.WriteLine();
}
Console.WriteLine("----------二维数组foreach遍历");
foreach (int q in Enumerable.Range(0, array.GetLength(0)))
{
foreach (int w in Enumerable.Range(0, array.GetLength(1)))
{
Console.Write(array[q, w] + " ");
}
Console.Write("\n");
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test
{
class Program
{
static void Main(string[] args)
{
int i = 1;
object o = i;//装箱
int j = (int)o;//拆箱
//Console.WriteLine(j);
//插入字符串
string str = "This is a girl.";
str = str.Insert(10, "buautiful ");
Console.WriteLine(str);
//填充字符PadLeft串
string str1 = "Hello World!";
string strleft = str1.PadLeft(15, '@');
string strright = str1.PadRight(15, '@');
Console.WriteLine(strleft + " " + strright);
Console.WriteLine("----------while");
int n = 1;
while (n <= 8)
{
Console.Write(n); n++;
}
Console.WriteLine("");
Console.WriteLine("----------do while");
int b = 1;
do
{
Console.Write(b); b++;
}
while (b <= 8);
Console.WriteLine("");
Console.WriteLine("----------数组");
//数组
int[] arr = new int[8]{1,2,3,4,5,6,7,8};
foreach (int item in arr)
{
Console.Write(item);
}
Console.WriteLine("");
Console.WriteLine("----------二维数组for遍历");
int[,] array = new int[,] { { 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 } };
for (int g = 0; g < 4; g++)//行的行数
{
for (int h = 0; h < 2; h++)//行的列数
{
Console.Write(array[g, h] + "\t");
}
Console.WriteLine();
}
Console.WriteLine("----------二维数组foreach遍历");
foreach (int q in Enumerable.Range(0, array.GetLength(0)))
{
foreach (int w in Enumerable.Range(0, array.GetLength(1)))
{
Console.Write(array[q, w] + " ");
}
Console.Write("\n");
}
}
}
}
相关文章推荐
- 【杭电2009】求数列的和
- 虚拟化四、KVM虚拟化技术
- java中“==”和equals方法的区别,再加上特殊的String引用类型
- php的写时复制
- 1初识IO
- 04-java小案例-调用函数-内存
- hdu4826Labyrinth-dp动态规划
- python核心编程十五章练习
- c printf格式总结
- 来来来, 出个面试题考一下你的实际开发经验
- POJ 2533 Longest Ordered Subsequence
- spring mvc无法访问controller的解决方法
- Python学习进程(13)文件与IO
- 变量的定义 scanf 的使用 简单运算符
- EasyDarwin开源流媒体云平台之语音对讲功能设计与实现
- hdu 3699 fzu 2009 A hard Aoshu Problem 枚举 模拟
- (4.1.27.11)Android动态加载so文件
- 【华为机试】题目+解答+自己不足+提升
- mysql如何选择合适的数据类型存储不同的数据
- NSURLConnection / NSURLSession/ SDWebImage