ASP.NET筆記試験問題

14333 ワード

原帖の住所を見てください:(間違いがあれば、指摘してください)
1-3問題の答え
  public enum QuestionType
    {
        Text=0,
        MultipleChoice=1
    }

    interface IQuestion
    {
         string Title { get; set; }

         QuestionType QueryType { get; }

         string GetAnswer();
    }

    abstract class QuestionBase : IQuestion 
    {
        private string title;
        public string Title
        {
            get
            {
               return title;
            }
            set
            {
                title = value;
            }
        }

        public string GetAnswer()
        {
            return "    ";
        }

        public QuestionType QueryType
        {
            get { throw new NotImplementedException(); }
        }
    }

    class TextQuestion : QuestionBase
    {
        public QuestionType QueryType
        {
            get { return QuestionType.MultipleChoice; }
        }

        public string GetAnswer()
        {
            return "    ";
        }
    }

    class MultipleChoiceQuestion : QuestionBase
    {
        public string GetAnswer()
        {
            return "    ";
        }
    }

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

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

    public static class Class1
    {
        /// 
        ///               
        /// 
        /// 
        /// 
        public static IQueryable WhereNotDeleted(this IQueryable products)
        {
            return products.Where(p => p.IsDeleted == "false");
        }
    }

5,sql语句:

  

select name,[year],[month],sum(amout) as income from [user],income where [user].id = income.userid group by name,[year],[month]

6,Linqは以上のクエリ結果を実現する
  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; }
    }

    public class GetResult
    {
        public List GetUserIncomeDtos(IQueryable users, IQueryable incomes)
        {
            var result = from income in incomes
                         group income by new { income.UserId, income.Year, income.Month } into g
                         join user in users on g.Key.UserId equals user.Id
                         select new UserIncomeDto
                         {
                             Name = user.Name,
                             Year = g.Key.Year,
                             Month = g.Key.Month,
                             Income = g.Sum(o => o.Amount)
                         };

            return result.ToList();
        }
    }

8,
    public static class VarDelegate
    {
        public static void Require(this TSource tSource, Funcstring> func, string exptionMsg)
        {
            if (string.IsNullOrEmpty(func(tSource)))
            {
                throw new Exception(exptionMsg);
            }
        } 
    }

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

ブログの内容を参考にして
転載先:https://www.cnblogs.com/lihfeiblogs/p/4110637.html