473,218 Members | 1,471 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,218 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 2309
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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.