Dynamically set value to static variable in C#

nauna
 
on May 19, 2022 03:27 AM
818 Views

hello,

i have class in which i have public static property.

i want to pass dynamic value to it instead of static string.

public static string hosts = "";
public string webconfiguration_description(string keyname)
{
    string returnvalue="";
    WebsiteSetup_Configuration wsc = db.WebsiteSetup_Configuration.FirstOrDefault(u => u.ConfigurationKey == keyname);
    if(wsc!=null)
    {
        returnvalue = wsc.Description;
    }

    return returnvalue;
}

so i have above method i want to this return method value to static property.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on May 19, 2022 03:29 AM

Use below code.

C#

public static string hosts = "";
public static string webconfiguration_description(string keyname)
{
    string returnvalue = "";
    WebsiteSetup_Configuration wsc = db.WebsiteSetup_Configuration.FirstOrDefault(u => u.ConfigurationKey == keyname);
    if (wsc != null)
    {
        returnvalue = wsc.Description;
    }

    return returnvalue;
}

Set using below code.

hosts = webconfiguration_description("as");