I started in 1983, in 2007 i still on a case!
Всем программистам привет! Respect! При выполнении данного модуля вылетает ошибка( работаю на визуал студио 2003, VC++, библиотека .net )
VS2003 An unhandled exception of type 'System.FormatException' occured in mscorlib.dll
Additional information :
Input string was not in a correct format
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System ;
using namespace System :: Collections ;
__gc class StringList // класс автом. сборки мусора
{
private :
static ArrayList *pList ;
public :
static int main()
{
pList = new ArrayList( 4 ) ;
ShowCount() ;
AddString( "Amy" ) ;
AddString( "Bob" ) ;
AddString( "Charlie" ) ;
ShowEnum( pList ) ;
ShowCount() ;
AddString( "David" ) ;
AddString( "Ellen" ) ;
ShowList( pList ) ;
ShowCount() ;
RemoveString( "David" ) ;
RemoveAt( 0 ) ;
ShowArray( pList ) ;
ShowCount() ;
RemoveString( "Amy" ) ;
RemoveAt( 3 ) ;
return 0 ;
}
private :
//================================================
static void ShowEnum( ArrayList *pArray )
{
IEnumerator *pIter = pArray -> GetEnumerator() ;
bool more = pIter -> MoveNext() ;
while ( more )
{
String *pStr =
dynamic_cast <String *> ( ( pIter -> Current ) ) ;
Console :: WriteLine( pStr ) ;
more = pIter -> MoveNext() ;
}
}
//================================================
static void ShowList( ArrayList *pArray )
{
IEnumerator *pEnum = pArray -> GetEnumerator() ;
while ( pEnum -> MoveNext() )
{
String *pStr =
dynamic_cast < String * > ( pEnum -> Current ) ;
Console :: WriteLine( pStr ) ;
}
}
//================================================
static void ShowArray( ArrayList *pArray )
{
for ( int i = 0 ; i < pArray -> Count; i++ )
{
Console :: WriteLine(
"pArray -> get_Item( { 0 } ) = { 1 }",
__box( i ),
pArray -> get_Item( i ) ) ;
}
}
//================================================
static void ShowCount()
{
Console :: WriteLine(
"pList -> Count = { 0 }", __box( pList -> Count ) ) ;
Console :: WriteLine(
"pList -> capacity = { 0 }", __box( pList -> Capacity ) ) ;
}
//================================================
static void AddString( String *pStr )
{
if ( pList -> Contains( pStr ) )
throw new Exception(
String :: Format( "list contains { 0 }", pStr ) ) ;
pList -> Add( pStr ) ;
}
//================================================
static void RemoveString( String *pStr )
{
if ( pList -> Contains( pStr ) )
pList -> Remove( pStr ) ;
else
Console :: WriteLine (
"List does not contain { 0 }", pStr ) ;
}
//================================================
static void RemoveAt( int nIndex )
{
try
{
pList -> RemoveAt( nIndex ) ;
}
catch( ArgumentOutOfRangeException * )
{
Console :: WriteLine(
"No element at index { 0 }",
__box( nIndex ) ) ;
}
}
//================================================
} ;
int main()
{
//StringList *p = new StringList ; //
//p -> main() ;
StringList :: main() ;
return 0 ;
}
//================================================
причем компилер ругается на строки типа :
Console :: WriteLine( "pList -> Count = { 0 }", __box( pList -> Count ) ) ;
заккоментив эти строки, ругательства продолжились на подобные, т е ошибка одинаковая, и как мне кажется связана с упаковкой
__box() . Подскажите как быть то.