c# - Why am I receiving a "call is ambigious" error when trying to user Math.Floor with an integer? -



c# - Why am I receiving a "call is ambigious" error when trying to user Math.Floor with an integer? -

i've made little programme uses floor method:

public static void main(string[] args) { int i; decimal[] t = new decimal[30]; for(i=0; i<t.length; i++) { t[i]=math.floor(i/6); } for(i=0; i<t.length; i++) { console.writeline(""+t[i]); } console.readkey(true); }

but doesn't work. sharpdevelop returns error:

the phone call ambiguous between next methods or properties: 'system.math.floor(decimal)' , 'system.math.floor(double)' (cs0121)

which related line:

t[i] = math.floor(i/6);

could explain me what's wrong?

also: @ first tried writing int[] t = new int[30]; since programme returns integers. returned sec error, saying should utilize type decimal instead of type int. tried utilize type float , type double didn't work either. seems type decimal works. know why?

could explain me what's wrong?

the compiler telling what's wrong - phone call ambiguous. fact you're trying utilize result of phone call assign decimal array irrelevant compiler - looks @ arguments method seek work out method want call.

the type of look i/6 int, , convertible both double , decimal, neither conversion beingness "better" other, phone call ambiguous. in fact, don't need phone call @ - you're performing integer arithmetic anyway look i / 6, truncates towards 0 - equivalent floor non-negative numbers. , you're wanting store integers anyway... need is:

public static void main(string[] args) { // while "values" isn't particularly descriptive name, it's improve // "t" int[] values = new int[30]; // limit scope of - declare in loop header (int = 0; < values.length; i++) { values[i] = / 6; } // don't need index here, utilize foreach loop. prefer // foreach on foreach (int value in values) { // don't need string concatenation here... console.writeline(value); } console.readkey(true); }

c#

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -