zoukankan      html  css  js  c++  java
  • 一些Asp.Net面试题答案

    工作时间长了总是用同样的一些东西  其他的有些生疏  闲来看看面试题练习一下:  题目出处嘛...aspnet-tests-for-juniors

    转载请注明来源:http://www.cnblogs.com/zaiyuzhong/p/answer-for-aspnet-test.html 

    1. 定义接口IQuestion:

    interface IQuestion

    {

      string Title{get;set;}

      QuestionType Type{get;}

      string GetAnswer();

    }

    小结: interface默认为internal, 可加上public, 只有这两种访问修饰符; 成员不能声明访问修饰符 全是public; 只包含方法、属性、事件或索引器的签名(其实全是方法);

    2. 定义抽象类QuestionBase:

    internal abstract class QuestionBase:IQuestion

    {

      public string Title{get;set;}

      public abstract QuestionType Type{get;}

      public virtual string GetAnswer()

      {

        return "默认答案";

      }

    }

    小结: 有默认实现的方法是虚方法, 通过 virtual 声明, 子类可重写可不重写;

    3. 定义TextQuestion,MultipleChoiceQuestion类:

    internal class TextQuestion:QuestionBase

    {

      public override QuestionType Type{get{return QuestionType.Text}}

      public override GetAnswer()

      {

        return "文本答案";

      }

    }

    MultipleChoiceQuestion 只有值不一样, 略

    小结: 题目没提示, 很可能忘记override Type属性;

    4. 完成扩展方法 WhereNotDeleted:

    public static class Tools

    {

      public static IEnumerable<Product> WhereNotDeleted(this IEnumerable<Product> sender)

      {

        return sender.Where(it => it.IsDeleted == "false");

      }

    }

    小结: 扩展方法是静态类的静态方法, 第一个参数this修饰;
        我有一些疑问: 1, Product的IsDeleted用bool类型比string要好;
        2, 不清楚这道题要考声明扩展方法还是筛选WhereNotDeleted, 如果是后者, 像我这样的答案应该是不行的;

    5. 写出Sql语句: (SQL语句关键字全大写是个人习惯)

    SELECT [Name],[Year],[Month],SUM([Amount]) AS Income
    FROM [User] INNER JOIN [Income] ON [User].Id=[Income].UserId
    GROUP BY [Name],[Year],[Mouth]

    小结: 应该是考联合查询和GROUP BY, 测了一下四种联合查询都可以(主外键的值都对应的上,可能提问会问到区别), 测试环境SQL Server 2014;

      这里有个坑 User(表名和内置函数User()冲突, 加[]表示xx), 开始写了一个简单的select怎么都报错, 以为自己多年不用SQL忘光了, 大囧;

    6. Linq语句得到5结果:

    var r = from u in users     join i in incomes on u.Id equals i.UserId     group i by new {u.Name, i.Year, i.Mouth} into temp     select new UserIncomeDto() {       Name = temp.Key.Name,       Year = temp.Key.Year,       Month = temp.Key.Month,       Income = temp.Sum(it => it.Amount)     }; return r.ToList();

    小结: 熟悉Linq...

    7. 修改HTML和路由:

    HTML:  <form action="..." method="post">

        <input name="username" type="text" placeholder="username" />

        <input name="password" type="password" placeholder="password" />

    Routes: routes.MapRoute(

          name: "MobileLogin"

          url: "/admin/mobile/user/login",

          defaults: new { controller = "User", action = "Login"}

          ); //注意路由顺序

    小结: form 可能会忘记声明method, 我不记得form默认是post还是get了, 还是声明一下的好;

    8. 完成Require方法:

    private void Require(Func<Product,string> selector, string msg)

    {

      var value = selector.Invoke(this);

      if(string.IsNullOrEmpty(value)) throw new Exception(msg);

    }

    小结: 这题好, 以前没注意过还可以这么造...

    如果是笔试, 这道题还是不错的, 有难度有区分, 中级开发者不借助VS不一定能写出来, 在后续的提问环节可以更好的了解应聘者的技术能力

    #region 2015-01-04 补充
    9. 现有蓝色底的纸板... :

    private void FillGround(Block ground, IEnumerable list)

    {

      //思路有点问题, 我先保存一下

      // 不行  这道题到我极限了.. 要研究一段时间了

    }

    #endregion

  • 相关阅读:
    HDU 3401 Trade
    POJ 1151 Atlantis
    HDU 3415 Max Sum of MaxKsubsequence
    HDU 4234 Moving Points
    HDU 4258 Covered Walkway
    HDU 4391 Paint The Wall
    HDU 1199 Color the Ball
    HDU 4374 One hundred layer
    HDU 3507 Print Article
    GCC特性之__init修饰解析 kasalyn的专栏 博客频道 CSDN.NET
  • 原文地址:https://www.cnblogs.com/zaiyuzhong/p/answer-for-aspnet-test.html
Copyright © 2011-2022 走看看