国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

答:我們公司的ASP.NET 筆試題,你覺得難度如何

2019-11-17 02:44:22
字體:
來源:轉載
供稿:網友

答:我們公司的asp.net 筆試題,你覺得難度如何

閑來無事,逛逛園子,發現有個面試題,覺得有意思。已自己的理解答來看看,不足之處,請多指教。

原文地址:http://www.survivalescaperooms.com/leotsai/p/aspnet-tests-for-juniors.html

第1:請定義一個接口IQuestion,有【標題】和【問題種類】兩個屬性,其中【問題種類】是只讀的枚舉類型QuestionType,另外還有一個方法獲取該問題的答案(無參,返回字符串)。

    public enum QuestionType    {        Text = 0,        MultipleChoice = 1    }    interface IQuestion    {        string Title { get; set; }        QuestionType QuestionType { get; }        string GetAnswer();    }

第2:請定義一個抽象類QuestionBase,實現第一題中的IQuestion接口,其中【問題種類】屬性不在該抽象類中實現,而留在該抽象類的子類中實現;獲取答案的方法有默認實現,返回字符串“默認答案”。

    public abstract class QuestionBase : IQuestion    {        public string Title { get; set; }        public abstract QuestionType QuestionType { get; }        public virtual string GetAnswer()        {            return "默認答案";        }    }

第3:請定義一個TextQuestion類,繼承自第2題中的QuestionBase;獲取答案的方法返回字符串”文本答案”。再定義一個MultipleChoiceQuestion類,繼承自第2題中的QuestionBase;獲取答案的方法返回字符串”單選答案”。

public class TextQuestion : QuestionBase    {        public override QuestionType QuestionType        {            get { return QuestionType.Text; }        }        public override string GetAnswer()        {            return "文本答案";        }    }    public class MultipleChoiceQuestion : QuestionBase    {        public override QuestionType QuestionType        {            get { return QuestionType.MultipleChoice; }        }        public override string GetAnswer()        {            return "單選答案";        }    }

第4:假設有實體類PRoduct定義如下:

  public class Product  {      public string Name { get; set; }      public string IsDeleted { get; set; }  }

現在有一個方法從IQueryable<Product>中獲取沒有刪除的Product列表,該方法實現如下:

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

請完成擴展方法:WhereNotDeleted

static class ProductExtend    {        public static IQueryable<Product> WhereNotDeleted(this IQueryable<Product> product)        {            if (product == null || product.Count() < 1) { return null; }            else { return product.Where(p => p.IsDeleted == "1"); }        }    }

第5:假設數據庫中有User和Income兩張表如下,請仔細分析下方的示例數據,然后寫出SQL得到右方的查詢結果。

191437386251620

分析圖片結果,可知,是User,Incom的聯合查詢,并根據月份合并了Amount的數據而得。

select name,[year],[month],sum([amount]) as income from [user] left join [income] on [user].id=[income].useridgroup by name,[year],[month] order by name

第6題:根據第5題的數據結構,有如下兩個實體類和查詢結果類的定義:

public class User{    public int Id { get; set; }    public string Name { get; set; }}public class Income{    public int Id { get; set; }    public int UserId { get; set; }    public decimal Amount { get; set; }    public int Year { get; set; }    public int Month { get; set; }}public class UserIncomeDto{    public string Name { get; set; }    public int Year { get; set; }    public int Month { get; set; }    public decimal Income { get; set; }}

現有一個方法用LINQ的方式得到第5題的查詢結果,該方法定義如下:

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

請完成該方法的實現。

public List<UserIncomeDto> GetUserIncomeDtos(IQueryable<User> users, IQueryable<Income> incomes)        {            //linq 實現            var data = from o in                           (                       from p in users                       join q in incomes                       on p.Id equals q.UserId                       select new { Name = p.Name, Year = q.Year, Month = q.Month, Income = q.Amount }                                  )                       group o by new { o.Name, o.Month, o.Year } into groupdata                       select new UserIncomeDto                       {                           Name = groupdata.Key.Name,                           Year = groupdata.Key.Year,                           Month = groupdata.Key.Month,                           Income = groupdata.Sum(p => p.Income)                       };            //泛型實現            var datal = users.GroupJoin(incomes, p => p.Id, q => q.UserId, (p, q) => new UserIncomeDto            {                Name = p.Name,                Year = q.Sum(o => o.Year),                Month = q.Sum(o => o.Month),                Income = q.Sum(o => o.Amount),            });            return data.ToList<UserIncomeDto>();        }

第7:在ASP.NET MVC應用程序中,假設有如下HTML表單:

<form action="/admin/mobile/user/login">     <input type="text" placeholder="username"/>    <input type="passWord" placeholder="password"/>     <input type="submit" value="login"/></form>
該表單同步提交的時候,如何修改以上HTML和路由配置以使該請求進入下方的action中:
public class UserController : Controller{    [HttpPost]    public ActionResult Login(string username, string password)    {        throw new NotImplementedException();    }}

我所能想到的就是在html的form表單添加屬性:method="post"

    <form action="/user/Login" method="post">    <input type="text" placeholder="username" name="username" />    <input type="password" placeholder="password" name="password" />    <input type="submit" value="login" />    </form>

第8題:請看如下代碼:

public class Product{    public string Name { get; set; }    public string Description { get; set; }    public void Validate1()    {        if (string.IsNullOrEmpty(this.Name))        {            throw new Exception("please enter a name for the product");        }        if (string.IsNullOrEmpty(this.Description))        {            throw new Exception("product description is required");        }    }    public void Validate2()    {        this.Require(x => x.Name, "please enter a name for the product");        this.Require(x => x.Description, "product description is required");    }}

請完成Validate2方法中Require方法的定義和實現,從而使得Validate2與Validate1方法實現同樣的效果。

public void Require(Expression<Func<Product, string>> query, string msg)        {            Func<Product, string> func = query.Compile();            if (string.IsNullOrEmpty(func(this)))            {                throw new Exception(msg);            }        }

評價:這幾個題目,咋一看感覺不難,仔細一作覺得不簡單,平心而論,考的很實用,偏重于C#基礎的應用。就當學習鞏固知識了,好久沒寫,有些語法感覺手生,但是思路還在,隨便寫寫, 不足之處請多指教。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 义乌市| 南宁市| 蚌埠市| 新竹市| 共和县| 嫩江县| 海淀区| 吐鲁番市| 大渡口区| 古浪县| 崇礼县| 东城区| 赣榆县| 文安县| 顺平县| 枣强县| 晴隆县| 通州市| 马尔康县| 阜城县| 曲麻莱县| 迭部县| 宁津县| 白水县| 济宁市| 屯门区| 大悟县| 若羌县| 崇文区| 久治县| 金昌市| 赤城县| 达日县| 博乐市| 仲巴县| 桂林市| 廊坊市| 吴桥县| 黔江区| 石屏县| 临沧市|