|
i am reading datas in text file and write into another text file..but getting exception ...
FileStream fs=new FileStream("C:\\Vicky\\DATAS\\1.txt",FileMode.OpenOrCreate,FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
FileStream fs1 = new FileStream("c:\\one.txt", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs1);
string[] s = new string[500];
for(int i = 0; i <= 500; i++)
{
s[i] = sr.ReadLine();
}
for (int j = 0; j <= 500; j++)
{
sw.WriteLine(s[j]);
}
sw.Close();
sr.Close();
fs.Close();
fs1.Close();
error is:
Index was outside the bounds of the array.in s[i]=sr.readline().....
|
|
|
|
|
An array is 0 based, so 500 elements are indexed from 0 to 499.
Just get rid of the = in the for cycles
|
|
|
|
|
thanks man....we got it.....can u explain me wat problem we did it ....explain it briefly.
|
|
|
|
|
An array is 0 based. So if the array contains 500 elements the first has index 0 and the last 499. In your for cycle (with <=) at the end you were trying to access to the element with index 500 that obviously is outside the bounds of the array.
http://msdn.microsoft.com/en-us/library/9b9dty7d(VS.80).aspx[^]
|
|
|
|
|
nettai wrote: explain it briefly.
You did it wrong.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
[0,499].Contains(500)==false
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
sorry man I'll try harder next time plz urgt
|
|
|
|
|
Hi All,
i'm trying to connect to the Deleted objects container in AD by using:
DirectoryEntry de = new DirectoryEntry("LDAP://CN=Deleted Objects,DC=domain,DC=com")
and it is retuning with an error saying - There is no such object on the sever. but i can see it when i use LDP!!
can anyone help?
Many Thanks,
phil
|
|
|
|
|
hi
i want to make a database in sql server 2000 using c# withoust using sql server enterprise manager, how it will be done? please help me i have searched alot but unable to find enough information
|
|
|
|
|
|
|
there is this thing called a book... In it they have examples and tell you how to do things. Plus if you want to make life hard for yourself with out using enterprise manager you should be able to do this yourself!
|
|
|
|
|
hi from where i can get that book, and there is a restriction cant use enterprise manager
|
|
|
|
|
Hello gurus,
I have a simple question for C# masters concerning controls.
I have a series of label with a formated name.
In a loop, I want to recover a pointer on the control (a label) by giving its name as a string.
for example:
<br />
Label lbl = null;<br />
string lblName = "";<br />
<br />
for (int i=0; i<5; i++)<br />
{<br />
lblName = "lblL" + i.ToString();
<br />
lbl = ???;
<br />
<br />
lbl.Text = i.ToString();<br />
}<br />
<br />
How to make the control pointing to the right one given its name?
I hope you understood my question in my poor english.
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
Hi Fred,
Would the following solve your problem:
lbl = new Label();
lbl = (Label)FindControl("lblName");
Ryan
|
|
|
|
|
Yes, that's it, in a recursive way and for WinForms.
There is no spoon.
modified on Thursday, March 12, 2009 10:41 AM
|
|
|
|
|
Sorry, my mistake. How about something like this:
Control myControl = new Control();
foreach (Control c in this.Controls)
{
if (c.Name == "lblName")
{
myControl = c;
}
}
|
|
|
|
|
Is this[^] what you looking?
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Something like that but for WinForms...
There is no spoon.
|
|
|
|
|
The is no FindContol method in WinForm. You can implenet your own
for this to work the control names need to be unique.
public static Control FindControl(string controlName)
{
if (!controlName.Empty)
return this.Controls.Find(controlName, true)[0];
return null;
}
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Ok, got it
Thanks.
There is no spoon.
|
|
|
|
|
you dont need to loop the controls, you can simple access it like an array and specify the control name, i.e.
Label lbl = (Label)Form1.Controls[lblName];
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
now i want to do the security code for atm program on consol application
like if the user of the ATM entered the Ac\No and the PIN CODE No 3 times wrong gives messege (the card has been confiscated please go to customer serviec).
i make the all program for ATM complately but this point i can not reach it
thanks
yours
btata
|
|
|
|
|
are you saying you have already done it, and you can not get it anymore?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
does your ATM gives out dispenses money?
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|