东软C++笔试题附答案

更新时间:2023-07-14 08:45:57 阅读: 评论:0

东软c++笔试题+答案
1、public static const int num = 9; 判断题
const 成员变量是静态的不需要加static修饰
2、C#中接口和类的主要区别问答
接口只包含方法或属性的声明,不包含具体实现方法的代码,接口可以实现多继承(可以实现多个接口),而类只能是单继承,继承(实现)接口的类必须实现接口中声明的方法或属性
3、用aled修饰的类有什么特点问答
不可被继承数轴练习题
4、找错误
指出下面程序的错误
public class MyTest
{
public void Test(ref int i)
{
i = 1;
}
public void Test(int i)
{
i = 1;
}
public void Test(out int i)
{
i = 1;
}
}
Out 和 ref 不能用来重载方法规则近义词
compiler error CS0663: "cannot define overloaded methods that differ only on ref and out"
5、什么类型的变量可以用foreach 来遍历?问答
In C#, it is not strictly necessary for a collection class to inherit from IEnumerable and IEnumerator in order to be compa tible with foreach; as long as the class has the required GetEnumerator, MoveNext, Ret, and Current members, it will work with foreach. Omitting the interfaces has the advantage of allowing you to define the return type of Current to be more specific than object, thereby providing type-safety.
6、读程序写出输出结果读程序
public class MyTest
{
static void Main(string[] args)
{
MyTest mt = new MyTest();
mt.Test();
}
public void Test()
{
StructPoint sp = new StructPoint();
sp.x = 9;
sp.y = 10;
StructPoint retSp = RefreshStructPoint(sp);
OutputStructPointResult(ref retSp);
OutputStructPointResult(ref sp);
retSp = RefreshStructPoint(ref sp);
OutputStructPointResult(ref retSp);
OutputStructPointResult(ref sp);
ClassPoint cp = new ClassPoint(10, 12);
ClassPoint retCp = RefreshClassPoint(cp);
OutputClassPointResult(ref retCp);
OutputClassPointResult(ref cp);
}
public void OutputStructPointResult(ref StructPoint sp)
{
Console.WriteLine(sp.x);
Console.WriteLine(sp.y);
}
public void OutputClassPointResult(ref ClassPoint cp)
{
Console.WriteLine(cp.X);
Console.WriteLine(cp.Y);
}
private StructPoint RefreshStructPoint(ref StructPoint point)        {
point.x++;
point.y++;
return point;
}
private StructPoint RefreshStructPoint(StructPoint point)
{
point.x++;
point.y++;
return point;
}
private ClassPoint RefreshClassPoint(ClassPoint point)        {
point.X = 0;
point.Y = 0;
return point;
}
}
public struct StructPoint
{
public int x;
public int y;
}
public class ClassPoint
{
private int x = 0;
private int y = 0;
羽球鞋public ClassPoint(int x, int y)
{
this.x = x;
this.y = y;
}
public int X
{
get
{
return x;
}
t
工程图学{
x = value;
}
}
public int Y
{
get
{
return y;
}
t
{
y = value;
}
}
}
输出结果
快快长大梳妆台效果图10
11
9
工作在职证明10
10
11
10
11
7、string 是值类型还是引用类型?下面的代码Main方法中在调用第一个Method 和第二个Method方法后str变量结果分别是什么,是否会被改变
class RefExample
{
香港是什么时候回归祖国的static void Method(ref string s)
{
s = "changedRef";
}
static void Method(string s)
{
s = "changed";
}
static void Main()
{
string str = "original";
Method(str);
Method(ref str);
}
}
第一个方法后str = “original”第二个方法后str = “changed Ref”
8、out和ref关键字的作用,有什么不同?
表示参数是传递引用,out传递前不需要初始化,执行的函数返回前必须赋值,ref传递前必须初始化

本文发布于:2023-07-14 08:45:57,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1095851.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:方法   接口   实现   传递
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图