关于完整解答Leo C.W博客中名为“我们公司的ASP.NET 笔试题,你觉得难度如何”的所有题目,请大家鉴定,不足之处,敬请指教!

第1到3题解答如下:

  1. public enum QuestionType
  2. {
  3. Text = ,
  4. MultipleChoice =
  5. }
  6.  
  7. public interface IQuestion
  8. {
  9. string Title { get; set; }
  10. QuestionType Category { get; }
    string GetAnswer();
  11. }
  12.  
  13. public abstract class QuestionBase : IQuestion
  14. {
  15. public string Title { get; set; }
  16. public abstract QuestionType Category { get; }
  17.  
  18. public virtual string GetAnswer()
  19. {
  20. return "默认答案";
  21. }
  22.  
  23. }
  24.  
  25. public class TextQuestion : QuestionBase
  26. {
  27. public override QuestionType Category { get { return QuestionType.Text; } }
  28.  
  29. public override string GetAnswer()
  30. {
  31. return "文本答案";
  32. }
  33. }
  34.  
  35. public class MultipleChoiceQuestion : QuestionBase
  36. {
  37. public override QuestionType Category { get { return QuestionType.MultipleChoice; } }
  38.  
  39. public override string GetAnswer()
  40. {
  41. return "单选答案";
  42. }
  43. }

第4题:

  1. public class Product
  2. {
  3. public string Name { get; set; }
  4. public string IsDeleted { get; set; }
  5. }
  6.  
  7. public static class ProductExtension
  8. {
  9. public static IQueryable<Product> WhereNotDeleted(this IQueryable<Product> query)
  10. {
  11. return query.Where(p => p.IsDeleted != "是");
  12. }
  13. }
  14.  
  15. public class ProductService
  16. {
  17. public List<Product> GetActiveProducts(IQueryable<Product> query)
  18. {
  19. return query.WhereNotDeleted().ToList();
  20. }
  21. }

第5

  1. select T1.Name,T2.[Year],T2.[Month],T2.InCome from [User] as T1 inner join
  2. (select UserId,[Year],[Month],COUNT(Amount) AS InCome from InCome group by UserId,[Year],[Month]) as T2
  3. on T1.Id=T2.UserId
  4. order by T2.UserId,T2.[Year],T2.[Month]
  1. select T1.Name,T2.[Year],T2.[Month],COUNT(T2.Amount) AS InCome from [User] as T1
  2. inner join InCome as T2 on T1.Id=T2.UserId
  3. group by T1.Name,T2.[Year],T2.[Month] order by T1.Name,T2.[Year],T2.[Month]

第6题:

  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. }
  23.  
  24. public class UserIncomeService
  25. {
  26. public List<UserIncomeDto> GetUserIncomeDtos(IQueryable<User> users, IQueryable<Income> incomes)
  27. {
  28. var resultList = (from u in users
  29. join newic in
  30. (from ic in incomes
  31. group ic by new { ic.UserId, ic.Year, ic.Month } into gp
  32. select new { gp.Key, InCome = gp.Sum(g => g.Amount) })
  33. on u.Id equals newic.Key.UserId
  34. orderby newic.Key
  35. select new UserIncomeDto() { Name = u.Name, Year = newic.Key.Year, Month = newic.Key.Month, Income = newic.InCome }).ToList();
  36.  
  37. return resultList;
  38. }
  39. }

第7

改HTML:

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

改路由:

  1. routes.MapRoute("UserLogin",
  2. "~/admin/mobile/{controller}/{action}",
  3. new { controller = "User", action = "Login" });

第8题:

  1. public class Product1
  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.  
  24. public void Require(Expression<Func<Product1, string>> expression, string errorMessage)
  25. {
  26. Func<Product1, string> func = expression.Compile();
  27.  
  28. if (string.IsNullOrEmpty(func(this)))
  29. {
  30. throw new Exception(errorMessage);
  31. }
  32. }
  33. }
  34.  
  35. public class TestProgram
  36. {
  37. public static void Main()
  38. {
  39. Product1 product1 = new Product1();
  40. try
  41. {
  42. product1.Validate2();
  43. }
  44. catch (Exception ex)
  45. {
  46. Console.WriteLine(ex.Message);
  47. }
  48. Console.Read();
  49. }
  50. }

更多IT相关的文章,欢迎光临我的个人网站:http://www.zuowenjun.cn/

关于完整解答Leo C.W博客中名为“我们公司的ASP.NET 笔试题,你觉得难度如何”的所有题目的更多相关文章

  1. 欢迎阅读daxnet的新博客:一个基于Microsoft Azure、ASP.NET Core和Docker的博客系统

    2008年11月,我在博客园开通了个人帐号,并在博客园发表了自己的第一篇博客.当然,我写博客也不是从2008年才开始的,在更早时候,也在CSDN和系统分析员协会(之后名为"希赛网" ...

  2. 修复在“Android 在ScrollView中嵌入ViewPage后ViewPage不能很好的工作的问题解决”这篇博客中MyScrollView出现滑动一会就不会上下滑动的问题

    在“Android 在ScrollView中嵌入ViewPage后ViewPage不能很好的工作的问题解决”,这篇博客中的大部分问题已经解决了. 唯一遗憾的是,ViewPage随人能够工作了,但是My ...

  3. 带图片的word快速插入到博客中

    最近在博客中写文章的时候,最烦的就是将word文档整体传到博客中,不能一次把图片粘贴上去,再次去添加图片的时候要截图还要找对位置才可上传,偶尔的机会在网上看到有人这么处理,挺好用的,这里我也做个备注. ...

  4. 在博客中显示图片_Mac版

    主要是防止自己忘掉 为了解决一开始自己想在写入的博客中添加本地图片,直接链接的话在自己的电脑倒是可以显示图片,但是在别人的电脑上就没办法加载图片了,问各路大神也没人愿意解答,百度也没有想要的答案,只好 ...

  5. 如何在hexo博客中在线阅读pdf

    前言 有一些资料或者笔记是pdf版本的,如果想要放在博客中进行阅读,那么就得将其转换为markdown格式或者html格式.但是这样转换后,其原pdf的格式就会混乱了,排版将会变得很困难,不过一山更比 ...

  6. 借用Snippet插件美化博客中的代码

    书写博客,难免要贴出代码.然而直接贴出代码,则不美观.于是,应运而生出现了很多代码美化的插件.其中比较有名的是Syntax Highlighting插件.   笔者在网上翻阅的时候发现了Snippet ...

  7. 在hexo静态博客中利用d3-cloud来展现标签云

    效果: http://lucyhao.com/tags/ hexo自带的tag cloud的标签展现不太美观,想能够展现出“云”效果的标签.在网上找到了d3-cloud这个项目,github地址:ht ...

  8. CSDN博客排名第一名,何许人也

    CSDN博客排名第一名,何许人也 一.提出问题 CSDN博客排名第一名,何许人也. 分析截止时间是:2013年12月19日星期四22:00. 二.博客网址 http://blog.csdn.net/p ...

  9. 2015年CSDN博客排名第一名,何方神圣?

    2015年CSDN博客排名第一名,何方神圣? 一.引子: 话说博主phphot,雄霸天下好多年. 俱往矣, 落花流水春去也. 斗转星移,江山易主. 详细可以参见下文: CSDN博客排名第一名,何许人也 ...

随机推荐

  1. MiniDao普通项目集成方案

    1.导入必要的jar包: 2.spring配置文件增加如下配置: <!-- Hibernate工具栏配置--> <bean id="miniDaoHiberCommonDa ...

  2. 奇怪吸引子---WimolBanlue

    奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...

  3. RabbitMQ的安装使用

    1.下载安装 Rabbit MQ 是建立在强大的Erlang OTP平台上,因此安装RabbitMQ之前要先安装Erlang. erlang:http://www.erlang.org/downloa ...

  4. iphone/ipad/ipod设置VPN(pptp连接方式)

    一.点击桌面上的-设置-图标进入设置(如图) 二.点击-通用-进入通用设置 三.点击-VPN-进入VPN设置(如图) 四.点击添加VPN设置进行设置 五.选择并连接

  5. oracle密码错误验证延迟

    补充从10g升级到11g之后需要注意的几个密码方面问题: 1. 11g默认开始密码区分大小写,可以通过把参数设置为SEC_CASE_SENSITIVE_LOGON =FALSE 屏蔽 2. 11g密码 ...

  6. Hive Streaming 追加 ORC 文件

    1.概述 在存储业务数据的时候,随着业务的增长,Hive 表存储在 HDFS 的上的数据会随时间的增加而增加,而以 Text 文本格式存储在 HDFS 上,所消耗的容量资源巨大.那么,我们需要有一种方 ...

  7. 查询反模式 - GroupBy、HAVING的理解

    为了最简单地说明问题,我特地设计了一张这样的表. 一.GROUP BY单值规则 规则1:单值规则,跟在SELECT后面的列表,对于每个分组来说,必须返回且仅仅返回一个值. 典型的表现就是跟在SELEC ...

  8. 浅析 mondrian 模式文件 Schema

    1.前言 前面几篇文章一经介绍过saiku.模式文件和MDX的关系.通俗点说模式文件(Schema)就是一个xml,里面定义了一个虚拟立方体,共MDX查询语言使用. 2.模式文件 Schema 最顶层 ...

  9. JIT

    http://www.cppblog.com/vczh/category/9583.html

  10. kail2在虚拟机上的安装

    首先先要安装虚拟机,打开安装包,下一步               选择典型 选择要安装到的目录,点下一步 4 输入密钥,下一步(密钥网上有很多我这边就例举一个,没用的话就自己找.我这个密钥是VM11 ...