所有的数组的遍历,都来自于IEnumerable,所以对IEnumerable的遍历
public
static
void
Print(IEnumerable myList)
{
int
i = 0;
foreach
(Object obj
in
myList)
{
if
(obj
is
Student)
//这个是类型的判断,这里Student是一个类或结构
{
Student s=(Student)obj;
Console.WriteLine(
"t[{0}]:t{1}"
, i++, s.Sname);
}
if
(obj
is
int
)
{
Console.WriteLine(
"INT:{0}"
,obj);
}
}
Console.WriteLine();
}
相关的:
if
(args ==
null
)
{
Console.WriteLine(
"args is null"
);
// Check for null array
}
else
{
Console.Write(
"args length is "
);
Console.WriteLine(args.Length);
// Write array length
for
(
int
i = 0; i < args.Length; i++)
// Loop through array
{
string
argument = args[i];
Console.Write(
"args index "
);
Console.Write(i);
// Write index
Console.Write(
" is ["
);
Console.Write(argument);
// Write string
Console.WriteLine(
"]"
);
}
}
Console.ReadLine();
Console.Write(
"请输入:"
);
string
contents = Console.ReadLine();
Console.WriteLine(
"刚输入的内容是:"
+ contents +
"——"
+ cTest.Contents);
Console.Read();