Click here to Skip to main content
15,887,350 members
Home / Discussions / C#
   

C#

 
GeneralRe: Index Out of Range Pin
ignrod6-Jul-12 17:28
ignrod6-Jul-12 17:28 
GeneralRe: Index Out of Range Pin
ASPnoob6-Jul-12 17:39
ASPnoob6-Jul-12 17:39 
AnswerRe: Index Out of Range Pin
Abhinav S6-Jul-12 17:57
Abhinav S6-Jul-12 17:57 
GeneralRe: Index Out of Range Pin
Trak4Net9-Jul-12 8:18
Trak4Net9-Jul-12 8:18 
AnswerRe: Index Out of Range Pin
Abhinav S6-Jul-12 17:57
Abhinav S6-Jul-12 17:57 
GeneralRe: Index Out of Range Pin
Roger Wright6-Jul-12 20:03
professionalRoger Wright6-Jul-12 20:03 
GeneralRe: Index Out of Range Pin
Abhinav S6-Jul-12 23:02
Abhinav S6-Jul-12 23:02 
GeneralRe: Index Out of Range Pin
ASPnoob7-Jul-12 0:27
ASPnoob7-Jul-12 0:27 
Hi, thank you all for responding. K is initialized outside of the function and I have modified my function as follows:
class Class1
{
private int k = 0;
private List<string> list1 = new List<string>();

//Passing in myTemp as a string
public string AddText(string myText)
{
int i = 0;
do
{
//check to see if element is empty
if (list1.Count == 0)
{
//Add the content of myText into list1
list1.Add(myText);
i++;
}
} while (i < list1.Count);

//Returns the content of the elements that were affected
return list1[i];
}
}
I have stepped through the function and Visual Studio says the line, return list1[i];is the cause of the error message "Index was out of range". I don't know what else to do. If you can explain why I'm getting the error by looking at my code, please point it out. Thanks for your help.

-- modified 7-Jul-12 9:16am.
GeneralRe: Index Out of Range Pin
Roger Wright7-Jul-12 6:52
professionalRoger Wright7-Jul-12 6:52 
GeneralRe: Index Out of Range Pin
Trak4Net9-Jul-12 22:11
Trak4Net9-Jul-12 22:11 
QuestionStatic IP? Pin
Midnight Ahri6-Jul-12 15:49
Midnight Ahri6-Jul-12 15:49 
AnswerRe: Static IP? Pin
PIEBALDconsult6-Jul-12 18:31
mvePIEBALDconsult6-Jul-12 18:31 
AnswerRe: Static IP? Pin
Midnight Ahri6-Jul-12 18:33
Midnight Ahri6-Jul-12 18:33 
AnswerRe: Static IP? Pin
SoMad6-Jul-12 19:59
professionalSoMad6-Jul-12 19:59 
GeneralRe: Static IP? Pin
Roger Wright6-Jul-12 20:59
professionalRoger Wright6-Jul-12 20:59 
GeneralRe: Static IP? Pin
SoMad7-Jul-12 16:31
professionalSoMad7-Jul-12 16:31 
GeneralRe: Static IP? Pin
Dave Kreskowiak7-Jul-12 2:47
mveDave Kreskowiak7-Jul-12 2:47 
GeneralRe: Static IP? Pin
SoMad7-Jul-12 16:28
professionalSoMad7-Jul-12 16:28 
AnswerRe: Static IP? Pin
Midnight Ahri8-Jul-12 15:02
Midnight Ahri8-Jul-12 15:02 
QuestionC# new linq to sql file problem Pin
dcof6-Jul-12 14:19
dcof6-Jul-12 14:19 
AnswerRe: C# new linq to sql file problem Pin
vinodkrebc6-Jul-12 20:18
vinodkrebc6-Jul-12 20:18 
GeneralRe: C# new linq to sql file problem Pin
dcof7-Jul-12 10:27
dcof7-Jul-12 10:27 
GeneralRe: C# new linq to sql file problem Pin
vinodkrebc7-Jul-12 17:12
vinodkrebc7-Jul-12 17:12 
QuestionC# add table to linq to sql file problem Pin
dcof6-Jul-12 14:17
dcof6-Jul-12 14:17 
QuestionC# filename, linenumber logging Pin
TheGreatAndPowerfulOz6-Jul-12 6:44
TheGreatAndPowerfulOz6-Jul-12 6:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.