object-initializers Questions

5

Solved

Is it somehow possible for properties to reference each other during the creation of a dynamic object an anonymously-typed object (i.e. inside the object initializer)? My simplified example below n...
Korwun asked 18/4, 2015 at 15:6

5

Solved

Certain collection types in .Net have an optional "Initial Capacity" constructor parameter. For example: Dictionary<string, string> something = new Dictionary<string,string>(20); List...
Hambrick asked 3/5, 2010 at 20:18

3

Solved

I'm just starting out with F# and I can't find the syntax to do object initialization like in C# 3. I.e. given this: public class Person { public DateTime BirthDate { get; set; } public string...
Stepup asked 16/12, 2008 at 16:44

2

Solved

I'm wondering if the use of object initializers inside using statements somehow prevents the correct disposal of the resource declared inside them, e.g. using (Disposable resource = new Disposable...
Culmination asked 25/7, 2019 at 13:55

5

Solved

Is there a way to step by step debug the object initializer code in Visual Studio? Example: return new Veranstaltung() { ID = tblVeranstaltung.VeranstaltungsID, Titel = tblVeranstaltung.Titel...
Auteur asked 30/3, 2011 at 16:47

2

Solved

Is there a way to generate a dictionary initializer using the C# CodeDom? Are those supported at all? I would like to have: private IDictionary<string, string> map = new Dictionary<strin...
Rosana asked 15/6, 2010 at 20:13

3

Solved

When I refactor the following line: Employee e = new Employee(); e.First = "Frank"; e.Last = "Rizzo"; using Resharper's "Use Object Initializer", I get the following: Employee e = new Employee ...
Overpay asked 20/1, 2010 at 20:57

3

Solved

Why isn't it possible to assign events along with properties in object initializers in C#? It seems to be so natural to do so. var myObject = new MyClass() { Property = value, Event1 = actor, ...
Flare asked 22/10, 2010 at 3:6

2

Solved

I create objects by initializing the fields in this way: class Example { public int a; public int b; } var obj = new Example { a = stream.ReadInt(), b = stream.ReadInt() }; Is it always for...
Abutment asked 24/12, 2017 at 8:14

4

Solved

I am using an object initializer for a st object: public class Container { public Container () { ContainedItem = new Item; } public Item ContainedItem { get; set; } } public class Item { publ...
Ingenious asked 20/7, 2017 at 10:6

1

In the below two sample code I am trying to instantiate a class named Test by using C# normal method and Object initializer. DateTime? nullDate = null; //this value will come from somewhere else ...
Evanston asked 23/11, 2016 at 15:55

2

Solved

Here is a complete simple working example import multiprocessing as mp import time import random class Foo: def __init__(self): # some expensive set up function in the real code self.x = 2 p...

8

Solved

With the following code I try to define a simple model class and it's failable initializer, which takes a (json-) dictionary as parameter. The initializer should return nil if the user name is not ...
Luxuriance asked 21/10, 2014 at 20:21

2

I'm interested in using the __new__ functionality to inject code into the __init__ function of subclasses. My understanding from the documentation is that python will call __init__ on the instance ...
Unconstitutional asked 14/1, 2016 at 4:39

4

How can I reinitialize an array in C? Should I define it through a pointer: int *data[], or can I just code: int data[] = {};? For example, I have defined it like: int main(void) { int data[] =...
Defend asked 20/3, 2012 at 4:45

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...

1

Solved

The following testcase throws a null-reference exception, when it tries to assign Id to an object which is null, since the code is missing the "new R" before the object initializer. Why is this no...
Presumably asked 3/6, 2015 at 12:58

3

Solved

Please note: this question is not the same as this question. I recently came across some C# syntax I hadn't previously encountered: Is there any way to do this in F#? class Two { public string ...
Urdar asked 5/5, 2014 at 2:10

2

Solved

I have these 2 classes: class Customer { public string Name; public string City; public Order[] Orders; } class Order { public int Quantity; public Product Product; } And then i...
Rightist asked 28/9, 2014 at 14:34

2

Solved

I use ReSharper everyday, and today I asked myself why ReSharper suggests "Use object initializer" when I do this : MyClass myClass = new MyClass(); myClass.MyInt = 0; myClass.MyString = string.Em...
Consolation asked 19/12, 2013 at 13:41

1

Solved

I recently came across this SO article and tweaked it for my scenario which follows: using System; using System.Collections.Generic; namespace ConsoleApplication18 { class Program { static voi...
Charlot asked 21/8, 2013 at 20:42

5

Solved

I've been learning the object initializer in C# recently, but now I'm wondering how it works when it conflicts with the constructor. public class A { public bool foo { get; set; } public A() { ...
Trackman asked 26/6, 2013 at 18:0

1

Solved

Resharper has just suggested the following refactoring to me: // Constructor initializes InitializedProperty but // the UninitializedSubproperty is uninitialized. var myInstance = new MyClass(); m...
Complexioned asked 28/5, 2013 at 14:42

4

Solved

I was reading This Article over on Jag Reeghal's blog and It seemed to me that what he was suggesting was really not the same thing as using an object initializer. Then I realized that I didn't rea...
Boisvert asked 18/4, 2011 at 0:29

26

Solved

My singleton accessor method is usually some variant of: static MyClass *gInstance = NULL; + (MyClass *)instance { @synchronized(self) { if (gInstance == NULL) gInstance = [[self all...

© 2022 - 2024 — McMap. All rights reserved.