Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
33 views

In an xUnit theory I'd like to send an InlineData parameter of type string[][]. I can't seem to get it right. Is it doable, and if so, how? I would expect this to work at least: [InlineData(new string[...
Kjell Rilbe's user avatar
  • 1,623
3 votes
1 answer
596 views

It appears that C# 12's collection initializers don't produce the same result as a ImmutableArray's Empty property; for example: using System; using System.Collections.Immutable; ...
Matthew Layton's user avatar
30 votes
2 answers
2k views

I'm reading Avalonia source code and I came across this sentence: return new MenuFlyoutPresenter { [!ItemsControl.ItemsProperty] = this[!ItemsProperty], [!ItemsControl.ItemTemplateProperty] = ...
Aleksander Stukov's user avatar
1 vote
2 answers
75 views

Context I have a List<T> of type Question. Class Question, in turn, contains a List<Answer>. Class Answer has a member called public Question Question { get; set; } which stores the ...
Amal K's user avatar
  • 4,988
2 votes
1 answer
584 views

I just stumbled upon the following issue: class Settings { // Let's set some default value: { 1 } public ICollection<int> AllowedIds = new List<int>() { 1 }; } static void Main(...
Heinzi's user avatar
  • 173k
1 vote
2 answers
151 views

I am using C# to hook into the FedEx API and I'm a bit stumped on how to modify some existing code to meet my needs. The snippet included is part of their canned code where they sample how to work ...
user1134307's user avatar
10 votes
4 answers
6k views

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<...
Battle's user avatar
  • 826
3 votes
3 answers
512 views

I'm creating a custom matrix class that only has a single 2D array to hold everything (I know that a 1D array is faster and better, but that's not the point of this implementation) the thing is, I'd ...
Raxmo's user avatar
  • 57
-2 votes
1 answer
72 views

can i insert a method/function in a collection initializer? i am trying to insert expression in the function within a collection initializer but the variable in the class is asking for the declaration ...
larca's user avatar
  • 9
-2 votes
1 answer
2k views

First of all, I don't even know what to use when passing on 4 parameters but no return value, I'll just use Func as an example. I do not want to use Dictionary.Add to insert my function, I want it to ...
Nils's user avatar
  • 5
1 vote
2 answers
66 views

I want initialize list with collection initializer values in class to make it available to use from separate functions: public Form1() { InitializeComponent(); } List<string> list = new ...
user avatar
2 votes
1 answer
405 views

I have a class with that has a collection-property: class MyClass { public MyCollection Coll { get; private set; } public MyClass() { this.Coll = new MyCollection(); } } class MyCollection : ...
MakePeaceGreatAgain's user avatar
0 votes
2 answers
191 views

In C# you can initialize an array like so: var example = new int[] { 1, 4, 3 }; As quoted in Custom Collection Initializers: The collection object to which a collection initializer is applied must ...
Stefan Wilms's user avatar
2 votes
1 answer
342 views

I would like to populate a collection using collection initializer that will call async methods: public class Diagnostics { public async Task<IEnumerable<DiagnosticsInfo>> Get() => ...
Jakub Konecki's user avatar
5 votes
1 answer
131 views

I have a custom Matrix class that I would like to implement a custom object initializer similar to what a double[,] can use but can not seem to figure out how to implement it. Ideally I would like ...
PlTaylor's user avatar
  • 7,613
1 vote
0 answers
171 views

C# 6 introduced some cool additions to how objects and collections are initialized. For example this code is valid in C#6: void Main() { var ints = new[] { 1, 2, 3, 4, 5 }; var myClass = new ...
Pavel Voronin's user avatar
21 votes
4 answers
7k views

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 = new ...
Royi Namir's user avatar
  • 149k
2 votes
0 answers
36 views

I have used collection initializer for a Dictionary and received a TypeInitializationException: public static Dictionary<Environment.SpecialFolder, string> specialFolders = new Dictionary<...
sharpener's user avatar
  • 1,903
2 votes
1 answer
568 views

Case This morning I refactored some Logging method and needed to change a method's 'params' parameter in a normal array. Consequently, the call to the method had to change with an array parameter. I'...
Herman Cordes's user avatar
7 votes
1 answer
7k views

I am converting some existing HTML to work with ASP.NET MVC, and have some forms containing input fields that have additional attributes (that, for now, I need to preserve) that contain a namespace ...
Richard Ev's user avatar
  • 54.3k
6 votes
2 answers
322 views

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 ...
Palo's user avatar
  • 1,121
4 votes
1 answer
2k views

What am I missing here? I expected the following to work just fine: public class ProposalFileInfo { public int FileId { get; set; } public bool IsSupportDocument { get; set; } } // ... var ...
Jonathan Wood's user avatar
11 votes
5 answers
11k views

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; } ...
GazTheDestroyer's user avatar
14 votes
2 answers
429 views

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 }; Any ...
Joan Venge's user avatar
  • 334k
4 votes
3 answers
178 views

I have a class that I created. I would like to allow the class to be able to have a collection initializer. Here is an example of the class: public class Cat { private Dictionary catNameAndType = ...
user489041's user avatar
  • 28.4k