我们公司的ASP.NET 笔试题,你觉得难度如何

本套试题共8个题,主要考察C#面向对象基础,SQL和ASP.NET MVC基础知识。

 

第1-3题会使用到一个枚举类,其定义如下:

1 public enum QuestionType
2 {
3     Text = 0,
4     MultipleChoice = 1
5 }

 

第1:请定义一个接口IQuestion,有【标题】和【问题种类】两个属性,其中【问题种类】是只读的枚举类型QuestionType,另外还有一个方法获取该问题的答案(无参,返回字符串)。

 

第2:请定义一个抽象类QuestionBase,实现第一题中的IQuestion接口,其中【问题种类】属性不在该抽象类中实现,而留在该抽象类的子类中实现;获取答案的方法有默认实现,返回字符串“默认答案”。

 

第3:请定义一个TextQuestion类,继承自第2题中的QuestionBase;获取答案的方法返回字符串”文本答案”。再定义一个MultipleChoiceQuestion类,继承自第2题中的QuestionBase;获取答案的方法返回字符串”单选答案”。

 

第4:假设有实体类Product定义如下:

1 public class Product
2 {
3     public string Name { get; set; }
4     public bool IsDeleted { get; set; }
5 }

现在有一个方法从IQueryable<Product>中获取没有删除的Product列表,该方法实现如下:

1 public List<Product> GetActiveProducts(IQueryable<Product> query)
2 {
3     return query.WhereNotDeleted().ToList();
4 }

请完成扩展方法:WhereNotDeleted

 

第5:假设数据库中有User和Income两张表如下,请仔细分析下方的示例数据,然后写出SQL得到右方的查询结果。

 

第6题:根据第5题的数据结构,有如下两个实体类和查询结果类的定义:

 1 public class User
 2 {
 3     public int Id { get; set; }
 4     public string Name { get; set; }
 5 }
 6 
 7 public class Income
 8 {
 9     public int Id { get; set; }
10     public int UserId { get; set; }
11     public decimal Amount { get; set; }
12     public int Year { get; set; }
13     public int Month { get; set; }
14 }
15 
16 public class UserIncomeDto
17 {
18     public string Name { get; set; }
19     public int Year { get; set; }
20     public int Month { get; set; }
21     public decimal Income { get; set; }
22 }

现有一个方法用LINQ的方式得到第5题的查询结果,该方法定义如下:

1 public List<UserIncomeDto> GetUserIncomeDtos(IQueryable<User> users, IQueryable<Income> incomes)
2 {
3     throw new NotImplementedException();
4 } 

请完成该方法的实现。

 

第7:在ASP.NET MVC应用程序中,假设有如下HTML表单:

1 <form action="/admin/mobile/user/login">
2     <input type="text" placeholder="username"/>
3     <input type="password" placeholder="password"/>
4     <input type="submit" value="login"/>
5 </form>

当该表单同步提交的时候,如何修改以上HTML和路由配置以使该请求进入下方的action中:

1 public class UserController : Controller
2 {
3     [HttpPost]
4     public ActionResult Login(string username, string password)
5     {
6         throw new NotImplementedException();
7     }
8 }

 

第8题:请看如下代码:

 1 public class Product
 2 {
 3     public string Name { get; set; }
 4     public string Description { get; set; }
 5 
 6     public void Validate1()
 7     {
 8         if (string.IsNullOrEmpty(this.Name))
 9         {
10             throw new Exception("please enter a name for the product");
11         }
12         if (string.IsNullOrEmpty(this.Description))
13         {
14             throw new Exception("product description is required");
15         }
16     }
17 
18     public void Validate2()
19     {
20         this.Require(x => x.Name, "please enter a name for the product");
21         this.Require(x => x.Description, "product description is required");
22     }
23 }

请完成Validate2方法中Require方法的定义和实现,从而使得Validate2与Validate1方法实现同样的效果。

 

第9题: 现有蓝色底的纸板,可以自定义长宽(W*H),定义好之后不能修改。现在提供N种规格的矩形小纸板, A ,B ,C ,D ........ 实际上最多不超过10种规格,选择其中的1种 或者 N种规格的纸板填充到底板上,如下图所示:

为了计算出最佳的选择方案:比如A 5个 C 1个 D 2个 使得底板的填充率最高,请提供具体的算法思路。

 

提示:比如下面这样的输入和输出:

 

输出:

 

posted @ 2014-11-19 14:42  Leo C.W  Views(16130)  Comments(166Edit  收藏  举报