📄 ch4_07.cs
字号:
using System;
class CH4_7
{
public static int PrintTwo( String[] args )
{
Console.WriteLine("Argument 1 {0} Argument 2 {1}", args[0], args[1] );
return 2;
}
public static int PrintOne( String[] args )
{
Console.WriteLine("Argument 1 {0}", args[0]);
return 1;
}
public static int PrintNone()
{
Console.WriteLine("You didn't supply the right number of arguments!");
return 0;
}
public static void Main(String[] args)
{
// Check for arguments. Use a nested if to handle
// two special cases.
if ( args.Length == 2 )
{
Console.WriteLine("Argument 1 {0} Argument 2 {1}", args[0], args[1] );
if ( args[0] == "Hello" )
Console.WriteLine("Well, hello yourself!");
}
// Alternatively, we could have a nested if-else statements
if ( args.Length == 2 )
{
Console.WriteLine("Argument 1 {0} Argument 2 {1}", args[0], args[1] );
}
else
if ( args.Length == 1 )
Console.WriteLine("Argument 1 {0}", args[0] );
else
Console.WriteLine("You didn't supply the right number of arguments!");
// We can do the same thing with a ternary operator. Warning: Its ugly!
Console.WriteLine("Printing... {0}", args.Length == 2 ? PrintTwo(args) :
args.Length == 1 ? PrintOne(args) :
PrintNone() );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -