Hi all,
I tried to set the initial value of a static field,But it does not pass compile.
How can I do this: initial value from Web.config or App.config.
My codes look like this:
Client:
using System;
using System.Text;
using Test;
namespace DEMO
{
class Client
{
static void Main(string[] args)
{
COMMON.Fun();
Console.ReadLine();
}
}
}
Class library:
using System;
using System.Text;
namespace Test
{
public static class COMMON // It will generate the DLL.
{
/*
Attempt to set the initial value of a static field.
Seek viable options?
*/
private static readonly string ConnString = System.Web.Configuration.WebConfigurationManager.
ConnectionStrings["SQLConnectionString"].ConnectionString;
static COMMON(){} // Static constructors
public static void Fun() {
Console.WriteLine("Connection String is:{0}",ConnString);
/*
TO DO SOMETHING ...
*/
}
}
}
Thanks.
Loading


VulpesRank #55 · 29.2K reputationPosted Jun 26, 2014, 8:18 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 26, 2014, 7:07 AM EDT
What's the compilation error?
Ken HRank #2,315 · 610 reputationPosted Jun 26, 2014, 7:13 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 26, 2014, 7:41 AM EDT
Ken HRank #2,315 · 610 reputationPosted Jun 26, 2014, 8:07 AM EDT
Ken HRank #2,315 · 610 reputationPosted Jun 26, 2014, 8:10 PM EDT
Do you have a solution?
Ken HRank #2,315 · 610 reputationPosted Jun 27, 2014, 1:07 AM EDT