public class Common
{
public SqlConnection Cnn { get; set; }
public enum Gender
{
Male,
Female,
Other
}
}
class Program
{
static void Main(string[] args)
{
Common common = new Common() { Cnn = new SqlConnection("Data Source=blogging.db") };
Console.WriteLine(common.Cnn.ConnectionString);
Console.WriteLine(Common.Gender.Female);
}
}
In your unusual design, the enum is accessed accessed through the class. Typically, enums are placed within a namespaces not a class. This same advice was given in
another one of your threads with the same subject.
I think you might be after the following pattern.
namespace ConsoleAppCS
{
public enum Gender
{
Male,
Female,
Other
}
public class Common
{
public SqlConnection Cnn { get; set; }
public Gender Gender { get; set; }
}
class Program
{
static void Main(string[] args)
{
Common common = new Common() {
Cnn = new SqlConnection("Data Source=blogging.db"),
Gender = Gender.Male
};
Console.WriteLine(common.Cnn.ConnectionString);
Console.WriteLine(common.Gender);
}
}
}
Member
46 Points
180 Posts
How to call Cnn & Gender in other classes
Jan 16, 2021 06:58 AM|jagjit saini|LINK
Hi
How to call Cnn in other classes
Thanks
All-Star
53041 Points
23612 Posts
Re: How to call Cnn & Gender in other classes
Jan 16, 2021 01:31 PM|mgebhard|LINK
Using a property is the normal design approach. Properties - C# Programming guide
Enums are named constants. Enumeration types (C# reference)
In your unusual design, the enum is accessed accessed through the class. Typically, enums are placed within a namespaces not a class. This same advice was given in another one of your threads with the same subject.
I think you might be after the following pattern.