C#练习题答案: 工作配对#1【难度:0级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

工作配对#1【难度:0级】:

答案1:

using StriveObjects;
using System;

public class Strive
{
  public static bool Match(Candidate c, Job j)
  {
    if (c.MinSalary == null || j.MaxSalary == null)
    {
      throw new Exception();
    }
    
    return (c.MinSalary * 0.9 <= j.MaxSalary);    
  }
}

答案2:

using StriveObjects;
using System;

public class Strive
{
  public static bool Match(Candidate c, Job j)
  {
    if (c.MinSalary == null || j.MaxSalary == null) {
      throw new Exception();
    }
    
    return c.MinSalary * 0.9 <= j.MaxSalary;
  }
}

答案3:

using StriveObjects;
using System;

public class Strive
{
  public static bool Match(Candidate c, Job j)
  {
    if(c.MinSalary==null||j.MaxSalary==null) throw new Exception();
    return c.MinSalary*0.9<=j.MaxSalary;
  }
}

答案4:

using StriveObjects;
using System;

public class Strive
{
    public static bool Match(Candidate c, Job j)
    {
        if (c.MinSalary == null || j.MaxSalary == null) throw new Exception();
        return (c.MinSalary * 0.9 <= j.MaxSalary);
    }
}

答案5:

using StriveObjects;
using System;

public class Strive
{
  public static bool Match(Candidate c, Job j)
  {
    if(c.Equals(null)) {
      throw new ArgumentException("A candidate is required");
    }
    if(j.Equals(null)) {
      throw new ArgumentException("A job is required");
    }
    if(c.MinSalary.Equals(null)) {
      throw new Exception("A minimum salary is required");
    }
    if(j.MaxSalary.Equals(null)) {
      throw new Exception("A maximum salary is required");
    }
    
    return (j.MaxSalary >= c.MinSalary * 0.9);
  }
}

答案6:

using StriveObjects;
using System;

public class Strive
{
  public static bool Match(Candidate c, Job j)
  {
    // Hack it!
    Console.WriteLine(c.MinSalary.GetType());
    Console.WriteLine(j.MaxSalary.GetType());
    
    return c.MinSalary * 0.9 <= j.MaxSalary;
  }
}

答案7:

    using StriveObjects;
    using System;

    public class Strive
    {
        public static bool Match(Candidate c, Job j)
        {
            if (c?.MinSalary is int &amp;&amp; j?.MaxSalary is int)
                return c.MinSalary*0.9 <= j.MaxSalary;
            else
                throw new FormatException(); 
        }
    }

答案8:

using StriveObjects;
using System;
public class Strive
{
    public static bool Match(Candidate c, Job j)
    {
        if (c == null || j == null || c.MinSalary == null || j.MaxSalary == null)
            throw new Exception();
        var min = c.MinSalary / 100.0 * 10.0;
        return c.MinSalary - min <= j.MaxSalary;
    }
}

答案9:

using StriveObjects;
using System;

public class Strive
{
  public static bool Match(Candidate c, Job j)
  {
    if (c.MinSalary is null) throw new ArgumentException();
    if (j.MaxSalary is null) throw new ArgumentException();
    
    return (c.MinSalary * 0.9) <= j.MaxSalary;
  }
}

答案10:

using StriveObjects;
using System;

public class Strive {
    public static bool Match( Candidate c, Job j ) {
        if ( c == null ) {
            throw new ArgumentNullException( );
        }
        if ( j == null ) {
            throw new ArgumentNullException( );
        }
        if ( c.MinSalary == null || c.MinSalary <= 0 ) {
            throw new ArgumentException( );
        }
        if ( j.MaxSalary == null || j.MaxSalary <= 0 ) {
            throw new ArgumentException( );
        }
        return c.MinSalary*0.9 <= j.MaxSalary;
    }
}

答案11:

using StriveObjects;
using System;

public class Strive
{
  public static bool Match(Candidate c, Job j) 
    => (c.MinSalary == null || j.MaxSalary == null) 
    ? throw new ArgumentException()
    : c.MinSalary * 0.9 <= j.MaxSalary;
}

答案12:

using StriveObjects;
using System;

public class Strive
{
  public static bool Match(Candidate candidate, Job job)
  {
    if (candidate.MinSalary == null) 
    {
      throw new ArgumentException($"{nameof(candidate)}.{nameof(candidate.MinSalary)}");
    }
    
    if (job.MaxSalary == null) 
    {
      throw new ArgumentException($"{nameof(job)}.{nameof(job.MaxSalary)}");
    }
    
    return job.MaxSalary >= 0.9 * candidate.MinSalary;
  }
}

答案13:

using StriveObjects;
using System;

public class Strive
{
  public static bool Match(Candidate c, Job j)
  {
    if (c.MinSalary == null || j.MaxSalary == null) { throw new ArgumentException(); }
    if ((c.MinSalary - (c.MinSalary*0.10)) <= j.MaxSalary) { return true; }
    return false;
  }
}



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值