Reputation: 61
.NET 5, ASP.NET Core MVC
I was defined a namespace with a type:
namespace Company.Services
{
public class APIService
{
// Some code here.
}
}
Then I defined other 2 classes in the APIService
:
namespace Company.Services
{
public class APIService
{
// Some code here.
public class APIObject{}
public class Parameters{}
}
}
Then I defined a method and try to instantiate these 2 classes:
namespace Company.Services
{
public class APIService
{
// Some code here.
public class APIObject{}
public class Parameters{}
public static APIObject[] Initialize(string strAPIS)
{
APIObject[] objs;
Parameters params; // Threw error here.
}
}
}
Then the complier threw an error: 'Parameters' is a 'type', which is not valid in the given context
, but the APIObject
had no error.
I don't know what happened.
Upvotes: 0
Views: 1412
Reputation: 38870
params
is a C# keyword, and as such can't be used as a variable name.
You should either call your variable @params
, or perhaps give it a different name altogether (maybe parameters
)?
Upvotes: 3