PC Review


Reply
Thread Tools Rate Thread

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

 
 
kk
Guest
Posts: n/a
 
      11th Jul 2008
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?

--
kk
 
Reply With Quote
 
 
 
 
Andrew Faust
Guest
Posts: n/a
 
      11th Jul 2008
This code worked fine for me using VS 2008 & .Net 3.5.

Andrew Faust

"kk" <(E-Mail Removed)> wrote in message
news:876674D8-0A33-4DD3-B70F-(E-Mail Removed)...
> 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?
>
> --
> kk


 
Reply With Quote
 
kk
Guest
Posts: n/a
 
      11th Jul 2008
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" <(E-Mail Removed)> wrote in message
> news:876674D8-0A33-4DD3-B70F-(E-Mail Removed)...
> > 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?
> >
> > --
> > kk

>

 
Reply With Quote
 
Pavel Minaev
Guest
Posts: n/a
 
      11th Jul 2008
On Jul 11, 9:42*pm, kk <k...@discussions.microsoft.com> wrote:
> 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.
 
Reply With Quote
 
kk
Guest
Posts: n/a
 
      15th Jul 2008
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<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?
>
> --
> kk

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count New to the List, Count Leaving the List, Count Total SteveC Microsoft Excel Misc 1 2nd Feb 2009 09:48 PM
Count number of times an entry for list B shows up in List A (cont BlueWolverine Microsoft Access Queries 1 3rd Jul 2008 06:43 PM
Excel 2000, count, sort a list & count totals? =?Utf-8?B?c3Vuc2xpZ2h0?= Microsoft Excel Worksheet Functions 1 9th Apr 2007 05:46 PM
How to count and group items in a list depending on size of list? Simon Lloyd Microsoft Excel Programming 3 13th Aug 2006 12:18 AM
How to count items in a list and group depending on size of list? Simon Lloyd Microsoft Excel Programming 5 28th Apr 2006 12:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:43 AM.