2015年4月25日星期六

.NET出现频率非常高的笔试题 - 邹琼俊

本邮件内容由第三方提供,如果您不想继续收到该邮件,可 点此退订
.NET出现频率非常高的笔试题 - 邹琼俊  阅读原文»

又到了金三银四的跳槽季,许多朋友又开始跳槽了,这里我简单整理了一些出现频率比较高的.NET笔试题,希望对广大求职者有所帮助。

一、.net基础

1、 a=10,b=15,请在不使用第三方变量的情况下,把a、b的值互换

答:小学算法,加法交换律和加法结合律
int a=a+b; int b=a-b;int a=a-b;

2、session喜欢丢值且占内存,Cookis不安全,请问用什么办法代替这两种原始的方法

答:redis 或者 memcache。当然,微软也提供了解决方案。iis中由于有进程回收机制,系统繁忙的话Session会丢失,可以用Sate server或SQL Server数据库的方式
存储Session不过这种方式比较慢,而且无法捕获Session的END事件。

3、如何处理几十万条并发数据?

答:用存储过程或事务。取得最大标识的时候同时更新..注意主键不是自增量方式这种方法并发的时候是不会有重复主键的..取得最大标识要有一个存储过程来获取.

4、62-63=1 等式不成立,请移动一个数字(不可以移动减号和等于号),使得等式成立,如何移动?

答案:62移动成2的6次方

5、<%# %> 和 <% %> 有什么区别?

答:<%# %>表示绑定的数据源,<% %>是服务器端代码块

6、ASP.Net页面生命周期简单描述

每个页面的生命周期为用户的每一次访问,也就是说每一次客户端与服务器之间的一个往返过程.全局变量的生命周期在此之间.

1. Page_Init();
2. Load ViewState and Postback data;
3. Page_Load();
4. Handle control events;
5. Page_PreRender();
6. Page_Render();
7. Unload event;
8. Dispose method called;

7、写出程序的输出结果
public abstract class A
{
public A()
{
Console.WriteLine(‘A’);
}
public virtual void Fun()
{
Console.WriteLine(“A.Fun()”);
}
}
public class B: A
{
public B()
{
Console.WriteLine(‘B’);
}
public new void Fun()
{
Console.WriteLine(“B.Fun()”);
}
public static void Main()
{
A a = new B();
a.Fun();
}
}

A
B
A.Fun()

8、 写出程序的输出结果:
public class A
{
public virtual void Fun1(int i)
{
Console.WriteLine(i);
}
public void Fun2(A a)
{
a.Fun1(1);
Fun1(5);
}
}

public class B : A
{
public override void Fun1(int i)
{
base.Fun1 (i + 1);
}
public static void Main()
{
B b = new B();
A a = new A();
a.Fun2(b);
b.Fun2(a);
}
}

2
5
1
6

9、在下面的例子里
using System;
class A
{
public A()
{
PrintFields();
}
public virtual void PrintFields(){}
}
class B:A
{
int x=1;
int y;
public B()
{
y=-1;
}
public override void PrintFields()
{
Console.WriteLine("x={0},y={1}",x,y);
}
当使用new B()创建B的实例时,产生什么输出?

答:X=1,Y=0;x= 1 y = -1

10、如何提高.NET的性能

1. 使用异步方式调用Web服务和远程对象
只要有可能就要避免在请求的处理过程中对Web服务和远程对象的同步调用,因为它占用的是的ASP.NET 线程池中的工作线程,这将直接影响Web服务器响应其它请求的能力。

2. 使用适当的Caching策略来提高性能

3. 判断字符串,不要用""比较。
//避免
if(strABC!=null && strABC!="")
{}
//推荐
if(!strABC.IsNullOrEmpty)
{}

4. 页面优化
5.用完马上关闭数据库连接
6. 尽量使用存储过程,并优化查询语句
7. 只读数据访问用SqlDataReader,不要使用DataSet
……….

11、说出一些数据库优化方面的经验?

索引内部原理:想象成Dictionary,插入、删除、更新的速度慢了,加上索引也多占用了空间,查询的速度快了。加上索引以后速度提升非常明显。

(1)在经常检索的字段上(select * from Person where Name=@Name)使用索引提高查询速度。

(2)select中只列出必要的字段,而不是*。

(3)避免隐式类型转换造成的全表扫描,在索引上使用函数也会造成全表扫描(因为索引只是为字段建立的,一旦使用表达式或者函数,那么索引就是失效了,当然也可以使用“函数索引”、
“表达式索引”解决这个问题),使用索引不一定能提高查询速度。

(4)避免在索引列上使用计算(where Name+'A'=@MyName)

......

二、程序设计

1.请编程实现一个冒泡排序算法?

Int[] arrAge = new int[5]; //给数组元素赋初始值
For(
int i=0; i<5; i++)
{
Int intTemp
= 0;
For(
int j=i+1; j<5; j++)
{
If(arrAge
<arrAge[j])
{
intTemp
= arrAge;
arrAge
= arrAge[j];
arrAge[j]
= intTemp;
}
}
}

2. 一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现。

public class MainClass
{
public static void Main()
{
Console.WriteLine(Foo(
30));
}
public static int Foo(int i)
{
if (i <= 0)
return 0;
else if(i > 0 && i <= 2)
return 1;
else return Foo(i -1) + Foo(i - 2);
}
}

3、编写一个单例(Singleton)类。

public FileManager
{
private FileManager(){}
public static FileManager Instance = new FileManager();
}

4. 程序设计: 猫大叫一声,所有的老鼠都开始逃跑,主人被惊醒。(C#语言)
要求: 1.要有联动性,老鼠和主人的行为是被动的。
2.考虑可扩展性,猫的叫声可能引起其他联动效应。

要点:1. 联动效果,运行代码只要执行Cat.Cryed()方法。2. 对老鼠和主人进行抽象
评分标准: <1>.构造出Cat、Mouse、Master三

iOS开发-UITableView自定义Cell - Fly_Elephant  阅读原文»

UITableView在iOS中开发的重要地位是毋庸置疑的,基本上应用中用到的比例是一半左右,而且大部分情况都是需要自定义单元格的,这样用户看到的App才能更有美感。之前写过UITableView的基本用法,如果对UITableView不是很熟悉可以参考本人之前的博客,因此很多UITableView的知识点就默认你已经熟悉了,先看下自定义实现的效果,这是自定义的Cell最后展现的效果:

自定义Cell

1.首先新建一个CustomCell.xib文件,方式如下:

2.新建一个继承自UITableViewCell的CustomTableViewCell类,需要重写initWithStyle方法:

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil];
self=[views firstObject];
}
return self;
}

3.CustomCell.xib中拖入一个UITableViewCell,然后和CustomTableViewCell关联:

关联之后CustomTableViewCell多了一个属性:

@property (weak, nonatomic) IBOutlet UILabel *title;

UITableView加载Cell

1.viewDidLoad初始化UITableView:

self.tableView=[[UITableView alloc]initWithFrame:CGRectMake(10, 10,CGRectGetWidth(self.view.bounds)-20, CGRectGetHeight(self.view.bounds)-10)];
self.tableView.delegate=self;
self.tableView.dataSource=self;
[self.view addSubview:self.tableView];

2.初始化标题数组travelArr

-(NSArray *)travelArr{
_travelArr=@[@"北京-清迈",@"北京-香港",@"北京-东京",@"北京-大阪",@"北京-新加坡",@"北京-维多利亚",@"北京-纽约",@"北京-夏威夷",@"北京-维多利亚",@"北京-柬埔寨"];
return _travelArr;
}

3.实现UITableViewDataSource中的方法: 

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.travelArr count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier=@"CustomCell";
CustomTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell==nil) {
cell=[[CustomTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
cell.title.text=[self.travelArr objectAtIndex:indexPath.row];
return cell;
}

4.实现UITableViewDelegate中的方法:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
return cell.frame.size.height;
}

简单的自定义大概就是如此了,如果有所收获,帮忙推荐下~


本文链接:iOS开发-UITableView自定义Cell,转载请注明。

阅读更多内容

没有评论:

发表评论