zoukankan      html  css  js  c++  java
  • 笔试题目1124

    本套试题共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 string 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方法实现同样的效果。

  • 相关阅读:
    计算两个字符串的最大公共字串的长度,字符不区分大小写
    任何一个整数m的立方都可以写成m个连续奇数之和。
    求一个byte数字对应的二进制数字中1的最大连续数
    Elasticsearch的过滤查询
    如何在Elasticsearch中安装中文分词器(IK+pinyin)
    使用Linux的alternatives命令替换选择软件的版本
    PHP如何与搜索引擎Elasticsearch交互?
    如何安装搜索引擎Elasticsearch?
    如何修改MAC自带的PHP的版本?
    程序员技能图谱
  • 原文地址:https://www.cnblogs.com/zhanying/p/4119979.html
Copyright © 2011-2022 走看看