الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

A problem with List type

مغلق
بدأه H@mis في 28 نوفمبر 2006 · 1 رد · 539 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

the problem in the cacArray list

?all values of the list take the last value entered and i don't know y

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;//4
namespace ConsoleApplication1
{
	class charAndCode
	{
		private string ch;
		private string code;//10

		public void setCAC(string[] strArray)
		{
			ch = strArray[0];
			code = strArray[1];
		}
		public void getCAC()
		{
			Console.WriteLine(ch);
			Console.WriteLine(code);//20
		}
	}
	class Program
	{
		static void Main(string[] args)//25
		{
			StreamReader sr = new StreamReader("H:\\sara.txt");
			string lineString;
			charAndCode cac = new charAndCode();
			List<charAndCode> cacArray = new List<charAndCode>(10);//30
			do
			{
				lineString = sr.ReadLine();

				string[] array = lineString.Split(' ');//35
				cac.setCAC(array);

				cacArray.Add(cac);

			} while (lineString != "c c");
			cacArray[2].getCAC();


		}//40
	}
}
#2

السلام عليكم ورحمة الله وبركاتة

:rolleyes:

اخي

المشكلة انك تبع السطر رقم 2 في المصفوفة

ولكن استبدل loop بهذا الكود

يمكن يمشي معاك

:^)

 int i = 0;
			do
			{
				lineString = sr.ReadLine();
				string[] array = lineString.Split(' ');//35
				cac.setCAC(array);
				cacArray.Add(cac);
				cacArray.getCAC();
			} while (lineString != "cc");

;)

هذا الموضوع مغلق.

مواضيع مشابهة