ambiguous error between C# 2002 and C#2008

  • Thread starter Thread starter Z.K.
  • Start date Start date
Z

Z.K.

I was going through Charles Petzold's book Programming Windows with C#
and everything was working fine until I tried typing in the
SysInfoPanel.cs program in Chapter 4. The program works fine in my
older Visual Studio 2002, but it gives me an ambiguous error on the
System.Math.Ceiling function in C# 2008 Express.


Error 1 The call is ambiguous between the following methods or
properties: 'System.Math.Ceiling(decimal)' and
'System.Math.Ceiling(double)' C:\Documents and Settings\xxxxxxxx\My
Documents\Visual Studio
2008\Projects\SysInfoPanel\SysInfoPanel\SysInfoPanel.cs 42 18 SysInfoPanel


I even ran the program from the CD with the same results. Why does the
2008 version of C# give me errors and how to fix it so that it works
like it is supposed to?

Z.K.


code:

readonly float cxCol;
readonly int cySpace;


panel.Size = new Size(
(int)Math.Ceiling(cxCol +
SysInfoStrings.MaxValueWidth(grfx, Font)),
(int)Math.Ceiling(cySpace * SysInfoStrings.Count));
 
Z.K. explained on 23-12-2008 :
I was going through Charles Petzold's book Programming Windows with C# and
everything was working fine until I tried typing in the SysInfoPanel.cs
program in Chapter 4. The program works fine in my older Visual Studio 2002,
but it gives me an ambiguous error on the System.Math.Ceiling function in C#
2008 Express.


Error 1 The call is ambiguous between the following methods or properties:
'System.Math.Ceiling(decimal)' and 'System.Math.Ceiling(double)' C:\Documents
and Settings\xxxxxxxx\My Documents\Visual Studio
2008\Projects\SysInfoPanel\SysInfoPanel\SysInfoPanel.cs 42 18 SysInfoPanel


I even ran the program from the CD with the same results. Why does the 2008
version of C# give me errors and how to fix it so that it works like it is
supposed to?

Z.K.


code:

readonly float cxCol;
readonly int cySpace;


panel.Size = new Size(
(int)Math.Ceiling(cxCol +
SysInfoStrings.MaxValueWidth(grfx, Font)),
(int)Math.Ceiling(cySpace * SysInfoStrings.Count));


The Math.Ceiling(decimal) overload was added in framework 2.0.

In your code the compiler can't decide what overload to use.
Try changing "cxCol" and "cySpace" to "double", so that the compiler
knows that the "Ceiling(double)" overload should be used.

Hans Kesting
 
Hans said:
Z.K. explained on 23-12-2008 :


The Math.Ceiling(decimal) overload was added in framework 2.0.

In your code the compiler can't decide what overload to use.
Try changing "cxCol" and "cySpace" to "double", so that the compiler
knows that the "Ceiling(double)" overload should be used.

Hans Kesting


Well, I thought about that and it does work as does changing cySpace to
float, but I guess what I really want to know is why does 2008 not work
and 2002 does? Or is the 2008 version just more restrictive as far as
the variable types go.

Z.K.

Roger
 
Back
Top