christoffer_tornell
christoffer_tornell
CC#
Created by christoffer_tornell on 1/5/2023 in #help
❔ DateTime culture info persistense
Hi! Say we have a DateTime variable called MyVariable. When I want to convert it into a string, I want to use a specific culture info. Usually, you just do MyVariable.ToString(MyCulture). But is there a way for me to set the culture info before the conversion? MyVariable.CultureInfo = MyCulture and then somewhere later MyString = MyVariable.ToString()
6 replies
CC#
Created by christoffer_tornell on 10/5/2022 in #help
Clean way of adding elements to IEnumerable
Is there a good way of adding an element to an IEnumerable without having to create a copy of the collection as such?:
var CatA = new Cat();
var CatB = new Cat();
IEnumerable<Cat> cats = new[]{ CatA };
var catList = cats.ToList();
catList.Add(CatB));
cats = catList;
var CatA = new Cat();
var CatB = new Cat();
IEnumerable<Cat> cats = new[]{ CatA };
var catList = cats.ToList();
catList.Add(CatB));
cats = catList;
What I want to do is something like this:
var CatA = new Cat();
var CatB = new Cat();
IEnumerable<Cat> cats = new[]{ CatA };
cats.ToList().Add(CatB));
var CatA = new Cat();
var CatB = new Cat();
IEnumerable<Cat> cats = new[]{ CatA };
cats.ToList().Add(CatB));
But ToList() makes a copy of the IEnumerable cats, and CatB is placed into the copy, instead of the IEnumerable cats.
14 replies