there is a class for getting settings

public class DbConfig { public class DbConf { public string Server; public string Port; } public List<DbConf> GetDbConf() { try { list.Add(new DbConf { Server = "34", Port = "34" }); }; return list; } catch (Exception msg) { logger.Debug(msg); return null; } } } 

how can i get data except

 foreach (var c in DbConfig.GetDbConf()) { Console.WriteLine("{0} {1}", c.Server, c.Port); } 
  • and what would you like? What do you want to see at the exit? - Dmitry
  • just like variables, accessible from anywhere in the program. something like c = DbConfig. GetDbConf (); Console.WriteLine ("{0}", c.Port); - des1roer
  • I understand, you do not need a list? - Dmitry
  • Yes, I want to see variables - des1roer
  • Well then catch the answer - Dmitry

1 answer 1

Judging by the comments list you have is redundant:

 public class DbConfig { public class DbConf { public string Server; public string Port; } public static DbConf GetDbConf() { var result = new DbConf(); try { result.Server = "34", result.Port = "34" return result; } catch (Exception msg) { logger.Debug(msg); return null; } } } 

call:

 var conf = DbConfig.GetDbConf(); // используем как = conf.Server 
  • and how to get the variables? - des1roer
  • @ des1roer updated - Dmitry
  • only var c = DbConfig. GetDbConf (); Console.WriteLine ("{0}", c.Server); - des1roer
  • @ des1roer well this is more convenient for you, I just showed the principle - Dmitry
  • Yes, you did not have a typo before the update. and so yes that's right - des1roer