I have a single module for a console application with an extension method in a separate Extensions
namespace and class, referred to in the DataProcessor
class with using Extensions;
, effectively as follows with extraneous code removed:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataProcessor
{
using Extensions;
class Program
{
public static int Main(string[] Args)
{
for (int CtrA = 0; CtrA <= 100; CtrA++)
{
System.Diagnostics.Debug.Print((CtrA + 1).Ordinal); // Error occurs here
}
}
}
}
namespace Extensions
{
public static class Extensions
{
public static string Ordinal(int Number)
{
string Str = Number.ToString();
Number = Number % 100;
if ((Number >= 11) && (Number <= 13))
{
Str += "th";
}
else
{
switch (Number % 10)
{
case 1:
Str += "st";
break;
case 2:
Str += "nd";
break;
case 3:
Str += "rd";
break;
default:
Str += "th";
break;
}
}
return Str;
}
}
I am getting a compile-time error on the line System.Diagnostics.Debug.Print((CtrA + 1).Ordinal);
, as well as everywhere else I use .Ordinal
as an int
method, stating:
'int' does not contain a definition for 'Ordinal' and no extension method 'Ordinal' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)
Can anyone tell me what I'm doing wrong?