C#数组_160921
来源:互联网 发布:淘宝寄错东西怎么办 编辑:程序博客网 时间:2024/06/04 18:25
double[] y = new double[3];声明部分跟C不同了。。。
y.length();可以直接查看数组长度
char[] b=new char[]{'a', 'b', 'c'};初始化
foreach循环使可以不依赖索引而读取每个数组元素,
=============一个栗子============================
int[] num = { 3, 34, 42, 2, 11, 19, 30, 55, 20 };
//int x;
foreach (int x1 in num)
{
if (x1 % 2 == 0)
Console.WriteLine(x1);
}
二维数组
int[ ,] arr=new int[2,3]//两个一维数组,每个数组包含3个变量,总共六个元素
访问arr[1,0]
======================一个栗子=========================
int[,] score = new int[4, 2] { { 89, 86 }, { 69, 40 }, { 64, 92 }, { 82, 100 } };
Console.WriteLine("the score are:");
for (int i = 0; i < score.GetLongLength(0); i++)
{
Console.WriteLine("语文:{0},数学{1}",score[i,0],score[i,1]);
}
======================================================
int.Parse(Console.RaedLine());//把输入转换为int型
string[] name = new string[5];
int[] score = new int[5];
for (int i = 0; i < name.Length; i++)
{
Console.Write("please input the name: ");
name[i] = Console.ReadLine();
Console.Write("please input the score: ");
score[i] = int.Parse(Console.ReadLine());
}
int sum = 0, avg;
for (int i = 0; i < name.Length; i++)
{
sum = sum + score[i];
}
avg = sum / 5;
Console.Write(avg);
- C#数组_160921
- C# 数组
- C#数组
- C#数组
- c# 数组
- C#数组
- C#数组
- c#数组
- C# 数组
- C#数组
- C#数组
- C#数组
- C#数组
- c#数组
- C#数组
- C#数组
- C#数组
- C#数组
- skyrtc demo
- BZOJ2087 [Poi2010]Sheep
- Fiddler抓包中文乱码问题
- 原型模式
- supervisord监控服务常用技巧
- C#数组_160921
- [kuangbin带你飞]专题七 线段树 E HDU 1698
- Grunt自动化web前端开发环境工具
- 第十五章上机练习4
- Leetcode 26 Remove Duplicates from Sorted Array
- 持续集成工具ant 入门使用指南
- jquery读书笔记(一)
- 禁止屏幕旋转
- MyEclipse updating indexes有什么用?