| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 563 人关注过本帖
标题:《C#编程起步》第五章笔记
只看楼主 加入收藏
Better
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2005-12-17
收藏
 问题点数:0 回复次数:2 
《C#编程起步》第五章笔记

第5章 更多的数据类型和运算符(原书章节安排得不太好,先看这章再看第4章)

5.1 数组
type[] array-name = new type[size];
方法一:
int[] sample = new int[10];
方法二:
int[] sample;
sample = new int[10];
方法三:
int[] sample = {0,11,84,239,2,79,12,7,-23,0,28};

5.2 多维数组
int[,] sample = new int[3,3];
int[,] sample = { {22,33,44},{55,66,77},{88,99,11} };

5.3 不规则数组
type[][] array-name = new type[size][]; //分配了列 行没有被分配

int[][] sample = new int[3][];
sample = new int[2];
sample = new int[3];
sample = new int[4];

5.4 数组引用变量赋值
(内容略)

5.5 使用长度属性
sample.Length
注意多维数组Length属性的使用 sample[0].Length

5.5 foreach循环
foreach (type identifier in expression) statement

type identifier 的类型。
identifier 表示集合元素的迭代变量。
expression 对象集合或数组表达式。
statement 要执行的嵌入语句。

using System;

class tempclass {
static void Main(){
int[] array = new int[10];
int sum = 0;
for(int i=0; i<10; i++){
array[i] = i;
}
foreach( int items in array ){
Console.Write(items);
sum += items;
}
Console.WriteLine();
Console.WriteLine("{0}",sum);
}
}

5.7 字符串
string str = "C# strings are powerful.";或

char[] charray = {'t','e','s','t'};
string str = new string(charray);

字符串也包括长度属性
string str = "test";
Console.WriteLine(str[0]);

与+一起使用
string str1 = "One";
string str2 = "Two";
string str3 = "Three";
string str4 = str1 + str2 + str3;

字符串数组:
string[] str = {"This" , "is" , "a" , "test."};

5.8 位运算符
位运算操作符只能操作整数,不能用于其它类型。
& 位与 | 位或 ^ 异或 >> 右移 << 左移 ~ 取反

p q p&q p|q p^q ~p
0 0 0 0 0 1
1 0 0 1 1 0
0 1 0 1 1 1
1 1 1 1 0 0

5.9 运算符“?”
exp1 ? exp2:exp3;

2006-03-16 22:17
xinxinren
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2006-4-14
收藏
得分:0 

好即努力,我来给你顶!


雨纷飞 飞在天空里是我的眼泪 泪低垂 垂在手心里是你的余味
2006-04-21 22:12
Vika
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2006-4-21
收藏
得分:0 
不错啊!!努力!!!!

2006-04-22 11:29
快速回复:《C#编程起步》第五章笔记
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019147 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved