C#+Database+ADO NET阶段小测试笔试题.docx
《C#+Database+ADO NET阶段小测试笔试题.docx》由会员分享,可在线阅读,更多相关《C#+Database+ADO NET阶段小测试笔试题.docx(15页珍藏版)》请在冰点文库上搜索。
![C#+Database+ADO NET阶段小测试笔试题.docx](https://file1.bingdoc.com/fileroot1/2023-6/11/6a032a17-9484-4e20-9d99-4b45c0e4c588/6a032a17-9484-4e20-9d99-4b45c0e4c5881.gif)
C#+Database+ADONET阶段小测试笔试题
一、选择题
1)
在C#语言的类定义体中,下面()访问修饰符可以访问该类的成员。
a)
private
b)
public
c)
internal
d)
以上选项均可
2)
在C#语言中,下面的()组变量名是正确的。
a)
voiddefine+WORD
b)
a3_b3_123YN
c)
for-abcCase
d)
a2stuIds#123
3)
为了保证下面C#代码正常执行,在下划线处应填写的代码是()。
publicclassStudent
{
privateint_Id;
privatestring_name;
publicvoidGetName(intid,stringname)
{
-------------------------------------------
}
}
a)
this._Id=id;
this._name=name;
b)
this.Id=_id;
this.name=_name;
c)
_Id=id;
_name=name;
d)
_Id=this.id;
_name=this.name;
4)
下面()C#语句能够创建一个10行20列的二维整数型数组。
a)
int[]arr=newint[10,20];
b)
int[]arr=intnew[10,20];
c)
int[,]arr=newint[10,20];
d)
int[,]arr=newint[20,10];
5)
下面正确的C#代码是()。
a)
voidShowInfo()
{
voidGetInfo();
Console.WriteLine("inShowInfo()");
}
voidGetInfo()
{
Console.WriteLine("inGetInfo()");
}
b)
voidShowInfo()
{
Console.WriteLine("inShowInfo()");
GetInfo();
}
voidGetInfo()
{
Console.WriteLine("inGetInfo()");
}
c)
voidShowInfo()
{
voidGetInfo();
Console.WriteLine("inShowInfo()");
GetInfo();
}
voidGetInfo()
{
Console.WriteLine("inGetInfo()");
}
d)
voidShowInfo()
{
voidGetInfo()
{
Console.WriteLine("inGetInfo()");
}
Console.WriteLine("inShowInfo()");
ShowInfo();
}
6)
下面是实现冒泡排序的C#代码,在下划线处应填写的代码是()。
for(inti=0;i<__①______;i++)
{
for(intj=0;j<__②___________;j++)
{
if(arr[j]>arr[j+1])
{
inttemp;
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
a)
①处:
arr.Length-1-i
②处:
arr.Length-1
b)
①处:
arr.Length-1-i
②处:
arr.Length
c)
①处:
arr.Length
②处:
arr.Length-1
d)
①处:
arr.Length-1
②处:
arr.Length-1-i
7)
在VisualStudio平台中,调试C#代码时,()快捷键是单步执行。
a)
F5
b)
F9
c)
F10
d)
F11
8)
C#语言中,紧随switch的条件表达式或变量不能是()类型。
a)
int
b)
double
c)
char
d)
string
10)
下面C#代码的运行结果如图,下划线处应填写的正确代码是()。
classMyClass
{
publicintAdd(①)
{
intz=x+y;
x++;
y++;
returnz;
}
staticvoidMain(string[]args)
{
MyClassmyClass=newMyClass();
inti=100,j=200,k;
Console.WriteLine("i的值是{0},j的值是{1}",i,j);
k=myClass.Add(②);
Console.WriteLine("i的值是{0},j的值是{1},k的值是{2}",i,j,k);
Console.Read();
}
}
a)
①处代码:
refintx,refinty
②处代码:
i,j
b)
①处代码:
intx,inty
②处代码:
i,j
c)
①处代码:
refintx,refinty
②处代码:
refi,refj
d)
①处代码:
intx,inty
②处代码:
refi,refj
11)
执行结果如图所示的C#代码是()。
a)
for(inti=0;i<20;i++)
{
if(i%5==0)
{
return;
}
Console.Write(""+i);
}
b)
for(inti=0;i<20;i++)
{
if(i%5==0)
{
Console.Write(""+i);
}
}
c)
for(inti=0;i<20;i++)
{
if(i%5==0)
{
continue;
}
Console.Write(""+i);
}
d)
for(inti=0;i<20;i++)
{
if(i%5==0)
{
break;
}
Console.Write(""+i);
}
12)
下面C#代码段中下划线处填写的错误代码是()。
publicstaticvoidMain()
{
floatmoney=20.53f;
}
a)
inti=(int)money;
b)
Console.WriteLine(int.Parse(money));
c)
Console.WriteLine(Convert.ToInt32(money));
d)
Console.WriteLine(money.ToString());
13)
下面C#代码要查找字符串str左侧第1次出现空格的位置,应在下划线处填写的代码是()。
stringstr,str1;
str="Iamastudent.MynameisXiaoMing.";
Console.WriteLine();
a)
str.Substring(7)
b)
str.Split("");
c)
str.IndexOf("")
d)
str.LastIndexOf("")
14)
C#语言中,声明数组的正确代码是()。
a)
int[]arr={1,2,3,4,5};
b)
intarr3[]={1,2,3,4,5};
c)
int[]arr2=newint[5]{1,2,3};
d)
int[]arr1=newint[]{1,2,3,4,5};
15)
对下面这段C#代码的描述错误的是()。
a)
publicstaticvoidMain()
{
constfloatPI=3.14f;
floatr,l;
r=6.5f;
l=r*2*PI;
Console.WriteLine(l);
}
b)
publicstaticvoidMain()
{
constfloatPI=3.14f;
floatr,l;
r=6.5f;
PI=2.1415926f;
l=r*2*PI;
Console.WriteLine(l);
}
c)
publicstaticvoidMain()
{
constfloatPI=3.14f;
floatr,l;
r=6.5;
l=r*2*PI;
Console.WriteLine(l);
}
d)
publicstaticvoidMain()
{
constfloatPI=3.14;
floatr,l;
r=6.5;
l=r*2*PI;
Console.WriteLine(l);
}
二、程序阅读题
1.写出下面程序的运行结果。
namespaceTest
{
classMyClass
{
staticvoidMain(string[]args)
{
inti,j,k;
for(i=0;i<5;i++)
{
for(j=6-i;j>=0;j--)
Console.Write("");
for(k=0;k<2*i+1;k++)
Console.Write("&");
Console.WriteLine("");
}
}
}
}
2.写出下面程序的运行结果。
classText
{
publicstaticvoidMain()
{
intx=5;
inty=x++;
Console.WriteLine(y);
y=++x;
Console.WriteLine(y);
}
}
3.写出下面方法的功能。
staticfloatFH()
{
floaty=0,n=0;
intx=Convert.ToInt32(Console.ReadLine());
while(x!
=-1)
{
n++;
y+=x;
x=Convert.ToInt32(Console.ReadLine()) ;
}
if(n==0)
returny;
else
returny/n;
}
4.写出下面程序的功能。
Arr[]{4,7,1,2,3}
voidfn(int[]arr,refintn)
{
n=0;
foreach(intxinarr)
{
if(nn=x;
}
Console.WriteLine(n);
}
5.写出下面程序的运行结果。
classMyClass
{
staticvoidMain(string[]args)
{
int[]arr=newint[]{101,23,45,6,45,356,22,99};
foreach(intiinarr)
{
if(i=101)
break;
}
Console.Read();
}
}
试题答案
一、选择题
1
2
3
4
5
d
b
ac
c
b
6
7
8
9
10
d
c
b
b
b
11
12
13
14
15
c
b
c
ad
a
二、程序阅读题
1.
2.
3.
求出从键盘接收的一组数据的平均值,以-1作为结束标志字符。
4.
求出一组数的最大值。
5.
编译出错。