Wrox Programmer Forums
|
BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4
This is the forum to discuss the Wrox book Beginning Microsoft Visual C# 2008 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, Eric White; ISBN: 9780470191354
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 6th, 2010, 08:26 PM
Authorized User
 
Join Date: Aug 2010
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Cade_Feng
Default Can't compile it pass

Code:
using System;
namespace Wrox.JackFeng{
	class Order{
		public Order(){}
		
		public void OrderNumber(int[] iArray){
			foreach(int val in iArray){
				Console.Write(val+'\t');
			}
		}
	}
}

using Wrox.JackFeng
namespace Wrox.CadeFeng
{
	class Program{
		static void Main(){
			const string sSuggestion="Please input some Number form(0-100)!";
			const int zero=0;
			string sNum = string.Empty;
			int[] iArray ;
			int i=zero;
			bool condition = false;
			
			Console.WriteLine(sSuggestion);
			while(!condition){
				sNum = Console.ReadLine();
				iArray[i] = Convert.ToInt32(sNum);
					i++;
				if(Convert.ToInt32(sNum)==0)
					break;
			}	
			
			Order Order_ = new Order();
			Order_.OrderNumber(iArray);
		}
	}
}
__________________
Wana be a .net developer.
Sincere yours
Cade_Feng
 
Old August 18th, 2010, 06:44 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default solution

Hello dear,

In C# when you declare an array, you should specify items count. for example:
Code:
int[] iArray = new int[20];
because you dont have specified length of array, you get error.
when you dont know length of array, you can resize the array.
or you can use generic lists:
Code:
using System;
namespace Wrox.JackFeng{
	class Order{
		public Order(){}
		
		public void OrderNumber(List<int> iArray){
			foreach(int val in iArray){
				Console.Write(val+'\t');
			}
		}
	}
}

using Wrox.JackFeng
namespace Wrox.CadeFeng
{
	class Program{
		static void Main(){
			const string sSuggestion="Please input some Number form(0-100)!";

			string sNum = string.Empty;

			List<int> iArray = new List<int>;
			
			Console.WriteLine(sSuggestion);
			while(1){
				sNum = Console.ReadLine();

				iArray.Add(Convert.ToInt32(sNum));


				if(Convert.ToInt32(sNum)==0)
					break;
			}	
			
			Order Order_ = new Order();
			Order_.OrderNumber(iArray);
		}
	}
}
click Thanks if it helps





Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass value to second page (create & pass var) ismailc ASP.NET 2.0 Basics 8 April 24th, 2010 07:03 AM
compile aspb ASP.NET 2.0 Professional 1 September 12th, 2006 10:22 AM
compile aspb ASP.NET 2.0 Basics 0 September 8th, 2006 10:27 AM
C# compile biran Visual Studio 2005 1 July 15th, 2005 01:36 PM
How Compile the First Example ? AlexPerusso BOOK: Beginning Visual C++ 6 3 April 8th, 2005 10:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.