我們公司的ASP.NET 筆試題,你覺得難度如何
來自: http://blog.jobbole.com/97846/
本套試題共8個題,主要考察C#面向對象基礎,SQL和ASP.NET MVC基礎知識。
第1-3題會使用到一個枚舉類,其定義如下:
public enum QuestionType
{
Text = 0,
MultipleChoice = 1
}
第1 題 :請定義一個接口IQuestion,有【標題】和【問題種類】兩個屬性,其中【問題種類】是只讀的枚舉類型QuestionType,另外還有一個方法獲取該問題的答案(無參,返回字符串)。
第2 題 :請定義一個抽象類QuestionBase,實現第一題中的IQuestion接口,其中【問題種類】屬性不在該抽象類中實現,而留在該抽象類的子類中實現;獲取答案的方法有默認實現,返回字符串“默認答案”。
第3 題 :請定義一個TextQuestion類,繼承自第2題中的QuestionBase;獲取答案的方法返回字符串”文本答案”。再定義一個MultipleChoiceQuestion類,繼承自第2題中的QuestionBase;獲取答案的方法返回字符串”單選答案”。
第4 題 :假設有實體類Product定義如下:
public class Product
{
public string Name { get; set; }
public bool IsDeleted { get; set; }
}
現在有一個方法從IQueryable中獲取沒有刪除的Product列表,該方法實現如下:
public List GetActiveProducts(IQueryable query)
{
return query.WhereNotDeleted().ToList();
}
請完成擴展方法:WhereNotDeleted
第5 題 :假設數據庫中有User和Income兩張表如下,請仔細分析下方的示例數據,然后寫出SQL得到右方的查詢結果。
第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; }
}</pre>
現有一個方法用LINQ的方式得到第5題的查詢結果,該方法定義如下:
public List GetUserIncomeDtos(IQueryable users, IQueryable incomes)
{
throw new NotImplementedException();
}
請完成該方法的實現。
第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();
}
}
第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");
}
}</pre>
請完成Validate2方法中Require方法的定義和實現,從而使得Validate2與Validate1方法實現同樣的效果。
第9題:現有藍色底的紙板,可以自定義長寬(W*H),定義好之后不能修改。現在提供N種規格的矩形小紙板, A ,B ,C ,D …….. 實際上最多不超過10種規格,選擇其中的1種 或者 N種規格的紙板填充到底板上,如下圖所示:
為了計算出最佳的選擇方案:比如A 5個 C 1個 D 2個 使得底板的填充率最高,請提供具體的算法思路。
提示:比如下面這樣的輸入和輸出:
輸出:
</div>