mardi 29 septembre 2015

Best way to define constant in asp.net

Which of below 2 method is better to declare constant/config driven variables in asp.net from coding standing perspective, from architecture perspective.

Type1-

class Constants
{
    public static string ConnectionString
    {
        get
        {
            //Get the connection string value from web.config
            if (ConfigurationManager.AppSettings["ConnectionString"] != null)
            {
                return ConfigurationManager.AppSettings["ConnectionString"];
            }
            else
            {
                return string.Empty;
            }
        }
    }
}

Type 2-

class Constants
{
    public static string ConnectionString = ConfigurationManager.AppSettings["ConnectionString"] != null ?
                                                ConfigurationManager.AppSettings["ConnectionString"] : string.Empty;
}

Is there any better way to ?

Aucun commentaire:

Enregistrer un commentaire