C#面试题
刚面试的几个基础题大家看下
1.两张表Employee(EID,EName,DepartId),Department(DepartId,DName),写SQL求每个部门有几个人(内连?)
2.1块钱1瓶酒,2个酒瓶换1瓶酒,写个方法求N块钱买几瓶酒(递归?)
3.写个方法求字符串长度,中文算2个字符(Encoding.Default.GetBytes(str).Length?)
4.写个方法求Array(a,b,c....)的最大值,不需排序(Array转换成数组然后Array.Sort()取第一个?)
------解决方案--------------------1.
SELECT EID,EName,(select count(*) from Department where DepartId=a.DepartId) as shuliang FROM Employee as a
2.
public int GetPing(int money)
{
int jiu = 0;
for (int i = 0; i < money; i++)
{
jiu++;
if (jiu % 2 == 0)
{
money++;
}
}
return jiu;
}
3.
int s = System.Text.Encoding.Default.GetBytes(str).length
4.
Array array = aaa;
int a = 0;
foreach (int b in array)
{
if (b > a)
a = b;
}