An enum is just a way to easily give names to underlying constant integer values to enhance code clarity..
It is unrelated to any particular instance of your Common class and so you can access it ionly through the class name (like for static members). as you declared this enum in a class.
It doesn't have to be declared inside a class, You can declare an enum directly in a namespace.
namespace Employee_Management.Models
{
public enum SrcType
{
SqlQuery,
StoredProcedure,
Table
}
public enum Gender
{
Male,
Female,
Other
}
public class Common
{
public Common()
{
var configuration = GetConfiguration();
Cnn = new SqlConnection(configuration.GetSection("CnnStrings").GetSection("Cnn1").Value);
}
}
}
Member
47 Points
186 Posts
Error - The Name SrcType does not exist in the current context
Jan 15, 2021 11:16 AM|jagjit saini|LINK
Hi
Thanks
All-Star
48710 Points
18171 Posts
Re: Error - The Name SrcType does not exist in the current context
Jan 15, 2021 11:49 AM|PatriceSc|LINK
Hi,
What if you try Common.SrcType.StoredProcedure? Or consider moving the enum out of Common class?
Member
47 Points
186 Posts
Re: Error - The Name SrcType does not exist in the current context
Jan 15, 2021 12:59 PM|jagjit saini|LINK
Hi PatricsSc
When i write like this it works - Common.SrcType.StoredProcedure
When i try like below it does not show SrcType after objCommon. Why is it so
Common objCommon = new Common();
objCommon
Thanks
All-Star
48710 Points
18171 Posts
Re: Error - The Name SrcType does not exist in the current context
Jan 16, 2021 09:15 AM|PatriceSc|LINK
An enum is just a way to easily give names to underlying constant integer values to enhance code clarity..
It is unrelated to any particular instance of your Common class and so you can access it ionly through the class name (like for static members). as you declared this enum in a class.
It doesn't have to be declared inside a class, You can declare an enum directly in a namespace.
Eidit; this is what they have done in ADO.NET ie https://docs.microsoft.com/en-us/dotnet/api/system.data.commandtype?view=net-5.0 is declared inisde the System.Data namespace.
Or do you even need to declare your own enum rather thnan to just use this one?
Member
47 Points
186 Posts
Re: Error - The Name SrcType does not exist in the current context
Jan 16, 2021 10:29 AM|jagjit saini|LINK
Hi PatriceSc
U mean to say i can declare it like below :-
Thanks