473,387 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
4 2314
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: matty.hall | last post by:
I have two classes: a base class (BaseClass) and a class deriving from it (DerivedClass). I have a List<DerivedClass> that for various reasons needs to be of that type, and not a List<BaseClass>....
5
by: PJ | last post by:
I have a class definition : public class PagingList<T> : List<T> { private int pageSize, pageNumber; public PagingList() { pageSize = (this.Count == 0) ? 1 : this.Count;...
9
by: Paul | last post by:
Hi, I feel I'm going around circles on this one and would appreciate some other points of view. From a design / encapsulation point of view, what's the best practise for returning a private...
7
by: Andrew Robinson | last post by:
I have a method that needs to return either a Dictionary<k,vor a List<v> depending on input parameters and options to the method. 1. Is there any way to convert from a dictionary to a list...
56
by: Zytan | last post by:
Obviously you can't just use a simple for loop, since you may skip over elements. You could modify the loop counter each time an element is deleted. But, the loop ending condition must be...
4
by: Peted | last post by:
I have the following code public enum pdfFlags { PFD_DRAW_TO_WINDOW, PFD_DRAW_TO_BITMAP, PFD_SUPPORT_GDI, PFD_SUPPORT_OPENGL, PFD_GENERIC_ACCELERATED, PFD_GENERIC_FORMAT,
35
by: Lee Crabtree | last post by:
This seems inconsistent and more than a little bizarre. Array.Clear sets all elements of the array to their default values (0, null, whatever), whereas List<>.Clear removes all items from the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.