fibonacci - Correction into the right direction C# -
so tried generate fibonacci algorithm in c# however, everytime run code getting error states:
the type or namespace name `ilist' not found. missing using directive or assembly reference?
i lost..where going wrong? thank you...
public ilist<int> generatefibonacci(int toindex) { ilist<int> sequence; sequence.add(0); sequence.add(1); (int i=0; i<toindex; i++) { sequence.add(sequence[i], sequence[i+1]); } return sequence; }
i bet miss system.collections.generic
, here correct version of program
using system; using system.collections.generic; namespace consoleapplication2 { public class program { public ilist<int> generatefibonacci(int toindex) { ilist<int> sequence = new list<int>(); sequence.add(0); sequence.add(1); (int = 0; < toindex; i++) { sequence.add(sequence[i]+ sequence[i + 1]); } return sequence; } static void main() { var s = generatefibonacci(10); console.readkey(); } } }
Comments
Post a Comment