没有合适的资源?快使用搜索试试~ 我知道了~
NIIT4考试复习资料整理\NIIT第四模块简答题考试重点
5星 · 超过95%的资源 需积分: 9 12 下载量 83 浏览量
2012-06-20
15:19:10
上传
评论
收藏 118KB DOC 举报
温馨提示
试读
11页
NIIT4考试复习资料整理\NIIT第四模块简答题考试重点,老师讲的和同学整理的
资源推荐
资源详情
资源评论
1. Consider that you want to store names of countries in a list. To do this
(1)First create an object of the ArrayList type;
(2)Second add the names of the required countries(Belgium, China, France, New
Zealand) one by one to this object by using the Add method;
(3)Finally, retrieve them by an index of country names.
Please write code for the task.
Ans:
ArrayList<string> arrayList=new ArrayList<string>();
arrayList.Add("Belgium");
arrayList.Add("China");
arrayList.Add("France");
arrayList.Add("NewZealand");
foreach(string str in arrayList)
{
Console.WriteLine(str);
}
2. Please write the result of following code.
Stack<string> numbers1 = new Stack<string>();
numbers1.Push("one");
numbers1.Push("two");
numbers1.Push("three");
numbers1.Push("four");
numbers1.Push("five");
Console.WriteLine("Peeking '{0}'", numbers1.Peek());
int count1 = numbers1.Count;
for (int i = 0; i < count1; i++)
{
Console.WriteLine("Popping '{0}'", numbers1.Pop());
}
Ans:
Peeking 'five'
Popping 'five'
Popping 'four'
Popping 'three'
Popping 'two'
Popping 'one'
1.use of Deep Clone、Shallow Clone(P1-48) (2956)
using System;
public class Invoice:ICloneable
{
private string _invoiceNo;
private float _amount;
private Customer _customer;
public Invoice(string invoiceNo,float amount)
{
this._invoiceNo=invoiceNo;
this._amount=amount;
}
public Customer Customer
{
get
{
return this._customer;
}
set
{
this._customer=value;
}
}
public override string ToString()
{
return string.Format("No:{0},Amount:{1,C},Customer:
{2}",this._invoiceNo,this._amount,this._customer.Name);
}
public object Clone()
{
Invoice inv=new Invoice(this._invoiceNo,this._amount);
Customer c=new Customer(this._customer.Name);
inv.Customer=c;
return inv;
}
static void Main(string[] args)
{
Invoice inv=new Invoice("0001",10000);
inv.Customer=new Customer("Stephen");
Invoice invClone=(Invoice)inv.Clone();
invClone.Customer.Name="Thomas";
Console.WriteLine(inv.ToString());
Console.WriteLine(invClone.ToString());
Console.Write("\nPress ENTER to exit...");
Console.ReadLine();
}
}
public class Customer
{
private string _name;
public Customer(string name)
{
this._name=name;
}
public string Name
{
get
{
return this._name;
}
set
{
this._name=value;
}
}
}
2.use of Coolection:Hashtable(P2-26)、List(P2-36) 、Stack /Queue(P2-17) (2956)
Stack:
Stack s1=new Stack();
s1.push("1");
s1.push("2");
s1.push("3");
s1.push("4");
s1.push("5");
Console.WriteLine("topmost element:"+s1.Peek());
Console.WriteLine("total elements:"+s1.Count);
while(s1.count>0)
{
Console.WriteLine(" "+s1.Pop());
}
Queue:
Queue q2=new Queue();
q1.Enqueue("1");
q1.Enqueue("2");
q1.Enqueue("3");
q1.Enqueue("4");
q1.Enqueue("5");
剩余10页未读,继续阅读
资源评论
- ltt832105682013-12-11好,有用,给力。
lmlmlmlmlmaf
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功