C# - initialize static class as non-static class? -


i have class:

[datacontract] public class connection {     [datamember]     public string username { get; set; }      public connection(string username)     {         username = username;     } } 

now need class as-is, in part of project use class this:

public static class connection {     public static string username { get; set; }      static connection()     {     } } 

is there way of merging code together, can use both versions of class in project (somewhere want have static, single instance of connection, somewhere else want have list of connections)?

you can merge code this:

[datacontract] public class connection {     [datamember]     public string username { get; set; }      public connection(string username)     {         username = username;     }      public static connection default { get; set; }      static connection()     {         default = new connection("username");     }  } 

... , use this:

list<connection> connections = new list<connection>(); 

.. or this:

string defaultconnectionusername = connection.default.username; 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -