K
kk
Personally I do not like the "sophisticated" code but,
anyway I have this (I squeez it to save a space):
using System;
using System.Collections.Generic;
public class SamplesArray {
public static void Main() {
// Creates and initializes a new integer array and a new Object array.
List<int> myIntList = new List<int>();
myIntList.AddRange (new int[5] { 1, 2, 3, 4, 5 } );
List<string> myStrList = new List<string>();
myStrList.AddRange (new string[2] { "aa","bb"} );
myStrList.Add("cc");
Console.WriteLine( "0:" + myStrList[0] );
Console.WriteLine( "2:" + myStrList[2] );
Console.WriteLine( "string List1: " );
PrintValues( myStrList );
Console.WriteLine();
myStrList.Clear();
myStrList.AddRange (new string[2] { "zz","yy"} );
Console.WriteLine( "0:" + myStrList[0] );
Console.WriteLine( "1:" + myStrList[1] );
Console.WriteLine( "string List2: " );
//PrintValues( myStrList );
Console.WriteLine();
Console.WriteLine( "integer array:" );
PrintValues( myIntList );
Console.WriteLine( "integer array size {0} [{1}]" , @"count:",
myIntList.Count );
}
public static void PrintValues( List<int> myList ) {
foreach ( int i in myList ) {
Console.Write( "\t{0}", i );
}
Console.WriteLine();
}
public static void PrintValues( List<string> myList ) {
foreach ( string i in myList ) {
Console.Write( "\t{0}\n", i );
}
Console.WriteLine();
}
}
gives:
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
Microsoft (R) Visual C# 2008 Compiler version 3.5.21022.8
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
0:aa
2:cc
string List1:
aa
bb
cc
0:zz
1:yy
string List2:
integer array:
1 2 3 4 5
integer array size count: [5]
AFTER uncommenting the //PrintValues( myStrList );
it gives:
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
Microsoft (R) Visual C# 2008 Compiler version 3.5.21022.8
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
0:aa
2:cc
string List1:
aa
bb
cc
0:zz
1:yy
string List2:
zz
yy
integer array:
1 2 3 4 5
integer array size count: [
WHERE is "5"
is it my mistake or BUG?
anyway I have this (I squeez it to save a space):
using System;
using System.Collections.Generic;
public class SamplesArray {
public static void Main() {
// Creates and initializes a new integer array and a new Object array.
List<int> myIntList = new List<int>();
myIntList.AddRange (new int[5] { 1, 2, 3, 4, 5 } );
List<string> myStrList = new List<string>();
myStrList.AddRange (new string[2] { "aa","bb"} );
myStrList.Add("cc");
Console.WriteLine( "0:" + myStrList[0] );
Console.WriteLine( "2:" + myStrList[2] );
Console.WriteLine( "string List1: " );
PrintValues( myStrList );
Console.WriteLine();
myStrList.Clear();
myStrList.AddRange (new string[2] { "zz","yy"} );
Console.WriteLine( "0:" + myStrList[0] );
Console.WriteLine( "1:" + myStrList[1] );
Console.WriteLine( "string List2: " );
//PrintValues( myStrList );
Console.WriteLine();
Console.WriteLine( "integer array:" );
PrintValues( myIntList );
Console.WriteLine( "integer array size {0} [{1}]" , @"count:",
myIntList.Count );
}
public static void PrintValues( List<int> myList ) {
foreach ( int i in myList ) {
Console.Write( "\t{0}", i );
}
Console.WriteLine();
}
public static void PrintValues( List<string> myList ) {
foreach ( string i in myList ) {
Console.Write( "\t{0}\n", i );
}
Console.WriteLine();
}
}
gives:
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
Microsoft (R) Visual C# 2008 Compiler version 3.5.21022.8
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
0:aa
2:cc
string List1:
aa
bb
cc
0:zz
1:yy
string List2:
integer array:
1 2 3 4 5
integer array size count: [5]
AFTER uncommenting the //PrintValues( myStrList );
it gives:
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
Microsoft (R) Visual C# 2008 Compiler version 3.5.21022.8
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
0:aa
2:cc
string List1:
aa
bb
cc
0:zz
1:yy
string List2:
zz
yy
integer array:
1 2 3 4 5
integer array size count: [
WHERE is "5"
is it my mistake or BUG?