C#の演習は答えるジョブマッチング#1 [難易度:0] - 、C#古典的なQ&Aをプログラミングを表示するには、挑戦するのを待っている1000回のC#の基本的な演習を

免責事項:この記事はブロガーオリジナル記事です、続くBY-SAのCC 4.0を著作権契約、複製、元のソースのリンクと、この文を添付してください。
このリンク: https://blog.csdn.net/weixin_45444821/article/details/102750631

ジョブマッチング#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);
  }
}

A6:

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

A7:

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

A8:

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

A9:

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




おすすめ

転載: blog.csdn.net/weixin_45444821/article/details/102750631