zoukankan      html  css  js  c++  java
  • ASP.NET 笔试题

    请看原帖地址:(如有错误,请指出)

    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<Product> GetActiveProducts(IQueryable<Product> query)
            {
                return query.WhereNotDeleted().ToList();
            }
        }
    
        public static class Class1
        {
            /// <summary>
            /// 获取所有没有被删除的扩展方法
            /// </summary>
            /// <param name="products"></param>
            /// <returns></returns>
            public static IQueryable<Product> WhereNotDeleted(this IQueryable<Product> 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<UserIncomeDto> GetUserIncomeDtos(IQueryable<User> users, IQueryable<Income> 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<TSource>(this TSource tSource, Func<TSource, string> 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");
            }
        }

    参考一下博客内容参考答案

  • 相关阅读:
    disruptor和ArrayBlockingQueue和LinkedBlockingQueue队列性能对比
    守护线程的作用和前台线程的区别
    tomcat导入idea作为maven项目
    百度网盘不限速
    netty ChannelOption参数 backlog 和 somaxconn同时设置才会生效
    dubbo的初探
    IDEA的常用快捷键
    Lucene简单了解和使用
    Hadoop的简单了解与安装
    Nginx的简单了解与使用
  • 原文地址:https://www.cnblogs.com/lihfeiblogs/p/4110637.html
Copyright © 2011-2022 走看看