问好!【难度:1级】:
答案1:
public class Greetings
{
public static string greet ( string name)
= > string . IsNullOrEmpty ( name) ? null : $"hello {name}!" ;
}
答案2:
public class Greetings
{
public static string greet ( string name) = >
( string . IsNullOrEmpty ( name) ) ? null
: $"hello {name}!" ;
}
答案3:
public class Greetings
{
public static string greet ( string s)
{
return s == null || s. Length == 0 ? null : "hello " + s + "!" ;
}
}
答案4:
public static class Greetings
{
public static string greet ( string name) = > string . IsNullOrEmpty ( name) ? null : $"hello {name}!" ;
}
答案5:
public class Greetings
{
public static string greet ( string name)
{
if ( string . IsNullOrEmpty ( name) )
return null ;
else
return $"hello {name}!" ;
}
}
答案6:
public class Greetings
{
public static string greet ( string name)
{
if ( name == "" || name == null )
return null ;
else
return $"hello {name}!" ;
}
}
答案7:
public class Greetings
{
public static string greet ( string nombre)
{
return ( nombre== null || nombre== "" ) ? null : $"hello {nombre}!" ;
}
}
答案8:
public class Greetings
{
public static string greet ( string name)
{
return ( name== null || name== "" ) ? null : $"hello {name}!" ;
}
}
答案9:
using System;
public class Greetings
{
public static string greet ( string name)
{
if ( name == null || name == String. Empty)
return null ;
return $"hello {name}!" ;
}
}
答案10:
public class Greetings
{
public static string greet ( string name)
{
if ( name == string . Empty || name == null )
{
return null ;
}
else
{
return $"hello " + name + "!" ;
}
}
}
答案11:
using System;
public class Greetings
{
public static string greet ( string name)
{
if ( String. IsNullOrEmpty ( name) ) return null ;
return String. Concat ( "hello " , name, "!" ) ;
}
}