Thomas
Thomas

Reputation: 34218

Nested class with static property access issue from outside c#

i have one main class and with in this main class i have another class A. class A has few static property and when i tried to access those static property from outside but getting error....not being possible

here is my classes structure

 public class EShip
{
    class Credentials
    {
        private static string _accessKey = "aaa";
        private static string _accessPwd = "xxx";
        private static string _accountNumber = "2222";

        public static string AccessKey
        {
            get { return _accessKey; }
        }

        public static string AccessPassword
        {
            get { return _accessPwd; }
        }

        public static string AccountNumber
        {
            get { return _accountNumber; }
        }
    }

    public static Credentials Credential
    {
        { get; }
    }
}

i try to expose that inner class by a main class property and from outside i try to do like

EShip.Credentials.AccessKey
EShip.Credentials.AccessPassword

it is not getting possible......suggest me good approach and why i am stuck. thnx.

Upvotes: 0

Views: 341

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460380

Class Credentials is not public, therefore it's not accessible. Change that and you're able to do:

String key = EShip.Credentials.AccessKey;

Access Modifiers (C# Programming Guide)

Upvotes: 2

Related Questions