By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,424 Members | 1,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,424 IT Pros & Developers. It's quick & easy.

C# net 3.50 - List<T>.Count - bug ?

P: n/a
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<intmyIntList = new List<int>();

myIntList.AddRange (new int[5] { 1, 2, 3, 4, 5 } );

List<stringmyStrList = 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<intmyList ) {
foreach ( int i in myList ) {
Console.Write( "\t{0}", i );
}
Console.WriteLine();
}
public static void PrintValues( List<stringmyList ) {
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?

--
kk
Jul 11 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
This code worked fine for me using VS 2008 & .Net 3.5.

Andrew Faust

"kk" <kk@discussions.microsoft.comwrote in message
news:87**********************************@microsof t.com...
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<intmyIntList = new List<int>();

myIntList.AddRange (new int[5] { 1, 2, 3, 4, 5 } );

List<stringmyStrList = 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<intmyList ) {
foreach ( int i in myList ) {
Console.Write( "\t{0}", i );
}
Console.WriteLine();
}
public static void PrintValues( List<stringmyList ) {
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?

--
kk
Jul 11 '08 #2

P: n/a
Did you get count 5 in both cases?

I have all updates applied - have the same result (BAD) in net 2.00 and 3.5

(You have to uncomment the line i mention!)

--
kk
"Andrew Faust" wrote:
This code worked fine for me using VS 2008 & .Net 3.5.

Andrew Faust

"kk" <kk@discussions.microsoft.comwrote in message
news:87**********************************@microsof t.com...
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<intmyIntList = new List<int>();

myIntList.AddRange (new int[5] { 1, 2, 3, 4, 5 } );

List<stringmyStrList = 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<intmyList ) {
foreach ( int i in myList ) {
Console.Write( "\t{0}", i );
}
Console.WriteLine();
}
public static void PrintValues( List<stringmyList ) {
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?

--
kk
Jul 11 '08 #3

P: n/a
On Jul 11, 9:42*pm, kk <k...@discussions.microsoft.comwrote:
Did you get count 5 in both cases?

I have all updates applied - have the same result (BAD) in net 2.00 and 3..5

(You have to uncomment the line i mention!)
Works fine here with uncommented line, though I have 3.5 SP1 beta.
Jul 11 '08 #4

P: n/a
My editor fault (UE32) - it is chopping buffer

NOT a BUG

thank you all for your time
--
kk
"kk" wrote:
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<intmyIntList = new List<int>();

myIntList.AddRange (new int[5] { 1, 2, 3, 4, 5 } );

List<stringmyStrList = 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<intmyList ) {
foreach ( int i in myList ) {
Console.Write( "\t{0}", i );
}
Console.WriteLine();
}
public static void PrintValues( List<stringmyList ) {
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?

--
kk
Jul 15 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.