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

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

練習題

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

練習題

public enum QuestionType {     Text=0,    MultipleChoice=1 }

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

interface IQuestion    {        string QuestionTitle { get; set; }        QuestionType QuestionType { get; set; }        string GetAnswer();           }

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

abstract class QuestionBase : IQuestion    {        string IQuestion.QuestionTitle { get; set; }        public abstract QuestionType QuestionType { get; set; }        public virtual string GetAnswer()        {            return "Default answer";        }    }

子類

class OneQuestion : QuestionBase    {        public QuestionType QuestionOneType;        public override QuestionType QuestionType        {            get { return QuestionOneType; }            set { QuestionOneType = value; }        }    }

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

class TextQuestion : QuestionBase {        public QuestionType QuestionOneType;        public override QuestionType QuestionType        {            get { return QuestionOneType; }            set { QuestionOneType = value; }        }        public override string GetAnswer()        {            return "Text Answer";        }    }    class MultipleChoiceQuestion : QuestionBase {        public QuestionType QuestionOneType;        public override QuestionType QuestionType        {            get { return QuestionOneType; }            set { QuestionOneType = value; }        }        public override string GetAnswer()        {            return "Sigle choice Answer";        }    }

第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 Extener    {        public static IQueryable<Product> WhereNotDeleted(this IQueryable<Product> query)        {            query = query.Where(t => t.IsDeleted == "NO");            return query;        }    }

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

SELECTb.`Name`,a.`Year`,a.`Month`,SUM(a.Amount) as "Income"FROMincome  a LEFT JOIN`user` bon a.UserId=b.IdGROUP BYa.`Month`,b.`Name`,b.id

第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(); }

請完成該方法的實現。

待定。。。。。。。。。

第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");    }}

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

class Products    {        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");                    }        public void Require(Func<Products,string> func, string s2) {                     if (string.IsNullOrEmpty(func(this))) {                throw new Exception(s2);            }        }                          }

原題的地址。。。http://www.survivalescaperooms.com/leotsai/p/aspnet-tests-for-juniors.html#!comments


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阳江市| 康保县| 旬阳县| 襄垣县| 桓仁| 江华| 昔阳县| 石棉县| 且末县| 沂源县| 乐陵市| 河西区| 鸡西市| 施秉县| 雷波县| 东安县| 宕昌县| 龙门县| 汝城县| 京山县| 沛县| 易门县| 文成县| 紫阳县| 彩票| 惠水县| 辽阳县| 竹溪县| 东城区| 育儿| 永清县| 靖宇县| 浦城县| 鹤岗市| 巴彦淖尔市| 蒲江县| 山西省| 兴安盟| 海宁市| 乡宁县| 海宁市|