d2jsp
d2jsp Forums > Programmer's Haven > C/C++/C# > Just Need A Little Help With This C# Bit > 2 Errors Cant Spot Them
Add Reply New Topic New Poll
Page 1 of 1
JesseD
#1 Jan 24 2018 02:57pm
Group: Member
Posts: 153
Joined: Aug 11 2014
Gold: 0.00
using System;
using System.Collections.Generic;

public class Hello
{
public static void Main()
{
// TODO: add your code here
string<int> primenumbers = new list<int>();
primenumbers.add(2);
primenumbers.add(3);
primenumbers.add(5);
primenumbers.add(7);
primenumbers.add(11);

// test code
Console.WriteLine(primeNumbers.Count);
Console.WriteLine(primeNumbers[0]);
Console.WriteLine(primeNumbers[1]);
Console.WriteLine(primeNumbers[2]);
Console.WriteLine(primeNumbers[3]);
Console.WriteLine(primeNumbers[4]);

}
}
JesseD
#2 Jan 24 2018 06:09pm
Group: Member
Posts: 153
Joined: Aug 11 2014
Gold: 0.00
YCX
#3 Jan 24 2018 09:48pm
Group: Member
Posts: 108
Joined: Jan 24 2009
Gold: 2,373.85
Check your formatting. Are you using Visual Studio? It should help you point out errors with red underlines.
Code
using System;
using System.Collections.Generic;

public class Hello
{
public static void Main()
{
// TODO: add your code here
List< int > primenumbers = new List<int>();
primenumbers.Add(2);
primenumbers.Add(3);
primenumbers.Add(5);
primenumbers.Add(7);
primenumbers.Add(11);

// test code
Console.WriteLine(primenumbers.Count);
Console.WriteLine(primenumbers[0]);
Console.WriteLine(primenumbers[1]);
Console.WriteLine(primenumbers[2]);
Console.WriteLine(primenumbers[3]);
Console.WriteLine(primenumbers[4]);

}
}
Rusemen
#4 Jan 27 2018 03:32pm
Group: Member
Posts: 2,688
Joined: Sep 24 2013
Gold: 0.00
primeNumbers.Count() ?
Yakir
#5 Feb 11 2018 04:38am
Group: Trade Assistant
Posts: 19,159
Joined: Dec 20 2005
Gold: 11,050.00
Trader: Mediator
Quote (JesseD @ Jan 24 2018 11:57pm)
using System;
using System.Collections.Generic;

public class Hello
{
public static void Main()
{
// TODO: add your code here
string<int> primenumbers = new list<int>();
primenumbers.add(2);
primenumbers.add(3);
primenumbers.add(5);
primenumbers.add(7);
primenumbers.add(11);

// test code
Console.WriteLine(primeNumbers.Count);
Console.WriteLine(primeNumbers[0]);
Console.WriteLine(primeNumbers[1]);
Console.WriteLine(primeNumbers[2]);
Console.WriteLine(primeNumbers[3]);
Console.WriteLine(primeNumbers[4]);

}
}


What is the output you want from that code?
ArcSten
#6 Feb 11 2018 12:06pm
Group: Member
Posts: 15,778
Joined: Jan 22 2010
Gold: 1,650.00
Trader: Trusted
Quote (JesseD @ 24 Jan 2018 21:57)
using System;
using System.Collections.Generic;

public class Hello
{
public static void Main()
{
// TODO: add your code here
string<int> primenumbers = new list<int>();
primenumbers.add(2);
primenumbers.add(3);
primenumbers.add(5);
primenumbers.add(7);
primenumbers.add(11);

// test code
Console.WriteLine(primeNumbers.Count);
Console.WriteLine(primeNumbers[0]);
Console.WriteLine(primeNumbers[1]);
Console.WriteLine(primeNumbers[2]);
Console.WriteLine(primeNumbers[3]);
Console.WriteLine(primeNumbers[4]);

}
}


the bold part should be a list also
gteich
#7 Feb 25 2018 09:01am
Group: Member
Posts: 95
Joined: Apr 8 2007
Gold: 0.00
Quote (JesseD @ Jan 24 2018 08:57pm)

string<int> primenumbers = new list<int>();
}


as pointed out above. I'd suggest to google some example with explanation how to create and fill lists in C#. Besides, your IDE should give you some kind of hint where and what went wrong here :)
ramilharvy
#8 May 21 2018 11:44pm
Group: Member
Posts: 1
Joined: May 21 2018
Gold: 0.00
try this....C# List

http://csharp.net-informations.com/collection/list.htm



This post was edited by ramilharvy on May 21 2018 11:45pm
Go Back To C/C++/C# Topic List
Page 1 of 1