Need in const string GET YEAR
C#
const string DATE_FORMAT = DateTime.Now.ToString('yyyy');Need in const string GET YEAR
const string DATE_FORMAT = DateTime.Now.ToString('yyyy');Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal YelveRank #178 · 13.6K reputationPosted Dec 15, 2022, 8:40 AM EST
Ill suggest to go with readonly
private readonly string _year = DateTime.Now.Year.ToString();Vishal YelveRank #178 · 13.6K reputationPosted Dec 15, 2022, 9:01 AM EST
public class Program { private readonly static string _year = DateTime.Now.Year.ToString(); static void Main(string[] args) { // Your code } }Goran BibicRank #993 · 2K reputationPosted Dec 15, 2022, 8:50 AM EST
Error CS0236 A field initializer cannot reference the non-static field, method, or property 'Program._year'
const string strCon2 = "Data Source=.\\SQLEXPRESS;Initial Catalog=BSS "+_year+";Integrated Security=True";