c#综合练习附答案
更新时间:2023-10-26 04:28:01 阅读量: 综合文库 文档下载
一、选择题
1. 下列程序所计算的数学式是( ) int a=0, i=2; while(i<100) {
a+=i; i+=2; }
A. a=1+2+4+…+98 B. a=1+2+4+…+100 C. a=2+4+6+…+98 D. a=2+4+6+…+100
2、下面是几条动态初始化一维数组的语句,其中正确的是( ) A、int[ ] arr2=new int[ ]; B、int[ ] arr2=new int[4 ];
C、int[ ] arr2=new int[i]{ 6,5,1,2,3}; D、int[ ] arr2=new int[4]{ 6,5,1,2,3};
3、用static关键字定义的静态方法,属于整个类而不属于( )。 A、类的某一个具体实例 B、类的其他方法 C、类的任何成员 D、常量 4、值参数是 参数( )。
A、按值传递 B、按地址传递 C、按引用传递 D、什么也不传递
5、类中两个以上的同名方法,只要 不同,编译器就知道调用哪个方法(A、参数类型 B、参数类型或参数个数 C、参数与顺序个数 D、返回类型 6、加载窗体时触发的事件是( )。
A、 Click B、Load C、GotFoucs D、DoubleClick 7、改变窗体的标题,需修改的窗体属性是( )。 A、Text B、Name C、Title D、Index
8、控件组合了Textbox控件和Listbox控件的功能( ) A、Label B、ComboBox C、StatusBar D、PictureBox 9.Textbox控件的PasswordChar属性的作用是( )。 A、该属性是Boolean类型,表示是否使用*号隐藏输入信息。 B、 该属性是String类型,表示输入的隐藏信息的实际内容
。 ) C、 该属性是Char类型,表示用哪个字符的隐藏输入的信息 ( ) D、 该属性在C#中未使用
9、 Timer的 事件在每个时间间隔内被重复激发。( )。 A、Click
B、Tick
C、ServerTick
D、Server Click
10、用户点击消息框按钮时返回值( )。
A、DialogValue B、DialogBox C、DialogResult D、DialogBox
二、填空题
1、 C#数组类型是一种引用类型,所有的数组都是从System命名空间的 类继承而来
的引用对象。 答案:object
2、一般将类的构造方法声明为 访问权限。如果声明为private,就不能创建该类的对象。
答案:public或公有
3、类中声明的属性往往具有get()和 两个函数。 答案:set()
4、对于方法,参数传递分为值传递和 两种。 答案:引用传递
5、传入某个属性的SET方法的隐含参数的名称是 。 答:value
6、C#提供一个默认的无参构造函数,当我实现了另外一个有一个参数的构造函数时,还想保留这个无参数的构造函数。这样我应该写 构造函数。 答:两个
7.装箱是把值类型转换到 类型。 答:引用类型
8.拆箱是引用类型返回到 类型。 答:值类型
9.C#的值类型包括 、 和 三种。 答:整数类型、浮点类型以及布尔类型
三、简答题
1.如何区别重载方法?
不同的参数类型,不同的参数个数,不同的参数顺序
2.C#用多种修饰符来表达类的不同性质。根据其保护级C#的类有五种不同的限制修饰符,请写出并指出它们之间的区别是什么? 答:
public 可以被任意存取
protected只可以被本类和其继承子类存取
internal只可以被本组合体(Assembly)内所有的类存取,组合体是C#语言中类被组合后的逻辑单位和物理单位,其编译后的文件扩展名往往是“.DLL”或“.EXE”。
protected internal唯一的一种组合限制修饰符,它只可以被本组合体内所有的类和这些类的继承子类所存取。
private只可以被本类所存取。
3. 编写一个类,利用方法重载完成二个整数、三个整数之和,在主函数中分别调用并输出和。
class Program {
public static int Add(int x, int y) {
return x + y; }
public int Add(int x, int y, int z) {
return x + y + z; }
static void Main(string[] args) {
Program program = new Program(); //实例化类对象 int x = 3; int y = 5; int z = 7;
//根据传入的参数类型及参数个数的不同调用不同的Add重载方法 Console.WriteLine(x + \ + y + \ + Program.Add(x, y));
Console.WriteLine(x + \ + y + \ + z + \ + program.Add(x, y, z)); Console.ReadLine(); } } }
4、设计一个成绩类,此类能够记录学生姓名、学号、成绩和科目,并且定义学生学号属性
class student {
public string name; public int no; public string sex; public float score; public string subject;
public string NO //创建学号属性
{
get {
return no; } set {
no = value; } } }
四、程序阅读题
1、using System; class Arraysort {
static void Main( ) {
int[] nums=new int[]{10,8,36,12,24}; foreach(int j in nums) {
Console.Write(“{0}\\0”, j); }
Console.WriteLine();
for(int j=nums.Length-1;j>=0;j--)
Console.Write (“{0}\\0”, nums[j]); Console.WriteLine();
} }
答案:10 8 36 12 24 24 12 36 8 10 2、 class Fruit {
public string color; public string shape;
public Fruit(string c, string s) {
color = c; shape = s; } }
class Test {
public static void Main() {
Fruit Orange = new Fruit(\
Console.WriteLine(\ }
}
答案:orange, round
3、using System; class Point {
public int x,y;
public Point(int x ,int y) {
this.x=x; this.y=y; } }
class Test { static void Main() { Point p=new Point(5,6); Console.WriteLine(\ Console.WriteLine(\ }
}
答案:x=5 y=6
4、class Decon1 {
public Decon1( )
{ Console.WriteLine(“调用构造函数Decon1”); }
~Decon1( )
{ Console.WriteLine(“调用析构函数Decon1”); } }
class Decon2 {
public Decon2( )
{ Console.WriteLine(“调用构造函数Decon2”); }
~Decon2( )
{ Console.WriteLine(“调用析构函数Decon2”); } }
class Test {
public static void Main()
{ Decon1 dec1=new Decon1( ); Decon2 dec2=new Decon2( ); } } 答案:调用构造函数Decon1 调用构造函数Decon2 5、 using System; class Test {
public void myMeth( ) {
int j;
for(j=1;j<10;j++) {
if(j%3==0) continue;
Console.WriteLine( “{0}\\t”,j); } }
static void Main( ) {Test lei=new Test( );
lei.myMeth( ); }
} 答案: 1
2 4 5 7 8
6、using System; class Test
{ public void myMeth( ) { int j= 8; if(j>=5) { j=j*2;
Console.WriteLine(j ); return; } else
{j=j*3;
Console.WriteLine(j ); return; } }
static void Main( ) { Test lei=new Test( ); lei.myMeth( ); }
} 答案:16
7、using System; class Test {
public void Swap(int x,int y) {
int k; k=x; x=y; y=k; }
static void Main() {
int a=8, b=68;
Console.WriteLine(\ Test sw=new Test(); sw.Swap(a, b);
Console.WriteLine(\} }
答案:a=8,b=68 a=8,b=68 8、 using System;
class TestoverLoad {
public void print(int i) {
Console.WriteLine(\输出的整数={0}\,i); }
public void print(string s) {
Console.WriteLine(\输出的字符串={0}\ s); }
public void print(double d) {
Console.WriteLine(\输出的双精度数={0}\,d); } }
class test {
public static void Main( ) {
TestoverLoad app=new TestoverLoad( ); app.print(6);
app.print(\理解方法重载了吗?\); app.print(3.14); } }
答案:输出的整数=6
输出的字符串=理解方法重载了吗?
输出的双精度数=3.14 9、class A {
public int count; public A() {
count = -1; }
public A(int n) {
count = n; } }
class Test {
static void Main() {
A a = new A();
Console.WriteLine(\ A b = new A(5);
Console.WriteLine(\ }
}
答案:count=-1
count=5
10、有以下程序,计算结果
static void Main(string[] args)
{ Console.Write(\输入一整数\ String s = Console.ReadLine(); int num = int.Parse(s); if (num++ > 5)
Console.WriteLine(num); else
Console.WriteLine(- -num); Console.Read(); }
运行时,从键盘输入5,则输出结果是:5
正在阅读:
c#综合练习附答案10-26
蒋介石的早年成长经历与个性特质12-05
大班绘本教案:搬过来,搬过去05-29
数据仓库技术白皮书之二08-25
简短七夕祝福语【优秀6篇】03-22
电梯电气安装作业人员考核题库04-20
湖北省无纸化学法用法练习 第九章 公务员依法行政常见违法问题11-06
创建国家级卫生县城工作检查评比记录05-24
2017年高三历史组复习计划04-20
这一年02-14
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- c#
- 练习
- 答案
- 综合
- 设计说明书 - 图文
- 南开15春学期《知识产权法》在线作业 答案
- 公共政策学论述题全解
- 毛概调研报告选题 调研报告参考选题方向 精品
- 15年历史学考研各校真题汇总
- 一滴眼泪换一滴水教案
- 2016考研调剂信息截止2-18(1)
- 从有效教学到高效教学
- 论再审证据
- 关于X-431电脑检测仪的使用方法 - 图文
- “马原”题库
- 对比租用设备和购买办公设备的成本与服务
- 数据结构 - 二叉树基本操作源代码
- HTCAD土方计算软件土方计算过程
- PMBOK第1-12章习题(附参考答案)-精简
- 小学二年级品德与生活《遇到困难的时候》教学设计
- 修坟日课案例1
- 高三全国卷名句默写押题
- 配套练习 - 第二篇建筑设计(建筑立、剖面)
- 肖临骏:高中历史史料教学的思考及实践