collection-initializer Questions
2
Solved
I'm reading Avalonia source code and I came across this sentence:
return new MenuFlyoutPresenter
{
[!ItemsControl.ItemsProperty] = this[!ItemsProperty],
[!ItemsControl.ItemTemplateProperty] = thi...
Lustihood asked 28/1, 2022 at 13:25
3
Solved
I want to initialize a list with an object and a list of objects in that specific order. Currently, I am doing:
List<MyObject> list = new List<MyObject>();
list.Add(object1); // object...
Sculpt asked 6/11, 2012 at 18:8
3
Solved
In a recent past there has been a lot of talk about whats new in C# 6.0
One of the most talked about feature is using Dictionary initializers in C# 6.0
But wait we have been using collection initia...
Brazier asked 2/12, 2014 at 7:37
5
Solved
I have a large static list which is basically a lookup table, so I initialise the table in code.
private class MyClass
{
private class LookupItem
{
public int Param1 { get; set; }
public int P...
Cooperation asked 8/2, 2012 at 13:36
4
Solved
I was thinking about arrays and lists and wondering if and how classes can get an implementation to be initializable like them. Let's take this class as basis:
class TestClass
{
private List<i...
Judas asked 13/9, 2018 at 12:52
1
Solved
Is it possible in C# to do something similar to the following?
var tigerlist = new List<Tigers>(){ Tail = 10, Teeth = 20 };
var tigers_to_cats_approximation = new List<Cat>()
{
forea...
Orola asked 31/7, 2018 at 18:26
1
Solved
I've been using C# for a while, but recently noticed that the behaviour of one of my unit tests changed depending on which variation of collection initialiser expression I used:
var object = new ...
Leaseback asked 31/7, 2017 at 7:32
4
Solved
I've read that :
The team have generally been busy implementing other variations on
initializers. For example you can now initialize a Dictionary object
But looking at :
var Dic = ne...
Eldwen asked 21/1, 2015 at 20:21
1
Solved
I am trying to add collection initializing to my class. I read about the initializers here: https://msdn.microsoft.com/en-us/library/bb384062.aspx#Anchor_2
I'll quote the important part that puzzl...
Horme asked 20/12, 2015 at 18:59
2
Solved
I have this simple code:
public static void Main(String[] args)
{
Data data = new Data { List = { "1", "2", "3", "4" } };
foreach (var str in data.List)
Console.WriteLine(str);
Console.ReadLin...
Latoshalatouche asked 9/10, 2015 at 12:0
2
Solved
Imagine this C# code in some method:
SomeClass.SomeGlobalStaticDictionary = new Dictionary<int, string>()
{
{0, "value"},
};
Let's say no one is using any explicit memory barriers or lock...
Medan asked 22/4, 2013 at 16:20
2
Solved
I always thought it worked fine both ways. Then did this test and realized it's not allowed on re-assignments:
int[] a = {0, 2, 4, 6, 8};
works fine but not:
int [ ] a;
a = { 0, 2, 4, 6, 8 };
...
Sutton asked 23/12, 2011 at 22:40
3
Solved
Can an attribute in C# be used with a collection initializer?
For example, I'd like to do something like the following:
[DictionaryAttribute(){{"Key", "Value"}, {"Key", "Value"}}]
public class Fo...
Absenteeism asked 3/8, 2011 at 20:4
3
Solved
Is is possible to combine a List initializer and object initializer at the same time?
Given the following class definition:
class MyList : List<int>
{
public string Text { get; set; }
}
//...
Platitudinize asked 6/6, 2011 at 15:16
2
Solved
Is it possible to implicitly declare next Dictionary<HyperLink, Anonymous>:
{ urlA, new { Text = "TextA", Url = "UrlA" } },
{ urlB, new { Text = "TextB", Url = "UrlB" } }
so I could use it...
Vitta asked 29/11, 2009 at 11:8
1
© 2022 - 2024 — McMap. All rights reserved.