Questions tagged [object-initializers]

Object initializers let you assign values to any accessible fields or properties of an object at creation time without having to invoke a constructor followed by lines of assignment statements.

An example of object initializers is the Object and Collection Initializers (C# Programming Guide):

Object initializers let you assign values to any accessible fields or properties of an object at creation time without having to invoke a constructor followed by lines of assignment statements. The object initializer syntax enables you to specify arguments for a constructor or omit the arguments (and parentheses syntax).

215 questions
1
vote
2 answers

How to make a formatted string property into a linq-to-entity friendly expression?

In a recent EF Code First project we were attempting to optimize some Linq queries using different techniques (don't worry its not premature). One common way to optimize a linq query is to convert more of the expression from Linq-to-Objects to…
1
vote
1 answer

Where is this variant on object initializers documented?

I did not see any explanation of this on MSDN:Object and Collection Initializers. Specifically, I've noted that it is possible to use an object initializer to set a property on a subType, rather than newing the sub-type itself. The syntax itself…
Brian
  • 25,523
  • 18
  • 82
  • 173
1
vote
1 answer

C++ undeclared identifier - object from .net dll class

I have a vb.net dll which I imported in an unmanaged c++ project. I successfully created an object of the class object using: CComPtr< IWSconnection > pIWSconnection; pIWSconnection.CoCreateInstance( __uuidof(IWSconnection ) ); Then, when I…
user228058
  • 465
  • 1
  • 7
  • 22
1
vote
4 answers

How to access an object in c#?

I'm having an object named data,which belongs to the class, [DataContract] public class names { [DataMember(Name = "code")] public int Code { get; set; } [DataMember(Name = "message")] public string Message { get; set; } …
Aju
  • 796
  • 3
  • 10
  • 29
1
vote
2 answers

Object Initializer vs Constructor in C# when many arguments are required

I'm developing a framework to access the EVE Online API from a C# Application. Essentially, the API works by the client sending a GET request to the EVE Online servers, the servers then send a response in the form of an XML file. My framework will…
Zymus
  • 1,673
  • 1
  • 18
  • 38
1
vote
2 answers

visual basic equivalent of "rectangle a=new a() { width=1; height=2; }"

rectangle a=new a() { width=1; height=2; } I used to construct objects like this, it there a similar way to do this in visual basic? I'm sorry I couldn't really label the technique.
Uğur Gümüşhan
  • 2,455
  • 4
  • 34
  • 62
1
vote
1 answer

How to assign a same value to different properties using Object Initializer

I try to assign a value to two different properties in object initializer and failed. In below code i try to assign Expand and Select properies to true. But i got the error 'The name Select doesnt exist in the current context' Here is my…
Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120
1
vote
1 answer

Difference between initializing with new operator and initializing with literal in Dart

In Dart, what is the difference between initializing a List with new operator and initializing it with literal? case 1: List args = new List(2); args[0] = 1; args[1] = 2; case 2: List args = [1, 2]; when I post the args to…
Andy.Tsao
  • 11
  • 1
1
vote
2 answers

Non static global object vs global pointer to dynamic object

Got an unexplained behaviour with the following: Case 1: a.cpp compiled as a .dll library and used in main() of main.cpp Bar b; //constr Bar::Bar(){ //... initialize members } //private library init Bar::init(){ ...} //public API init bool…
0
votes
1 answer

How to I pass the object itself (like how we can do in C#) in mootools?

I would like to know how to pass self to an other object in mootools, I am trying to build classes based on mootools class declaration, but i am noticing i cannot send the object itself using this when i use this it sends DOMWindow instead of World…
user677607
0
votes
4 answers

Using a KeyValuePair<> as Property vs. Separate Class vs. something else

What is the proper way to show "Admin Tables" in my "Business Objects"? I have the following on my Address object. public class Address { public int AddressID { get; set; } public KeyValuePair County { get; set; } …
Refracted Paladin
  • 12,096
  • 33
  • 123
  • 233
0
votes
3 answers

initialize the proprty of a class, which is of another type, by extension method and object initializers

. . List entries = null; using (SqlCeDataReader rdr = cmd.ExecuteReader()) { entries = rdr.Select(r => new DailyEntry { ID = int.Parse(r["Col_ID"].ToString()), Amount = decimal.Parse(r["Col_Amount"].ToString()), …
techBeginner
  • 3,792
  • 11
  • 43
  • 59
0
votes
1 answer

Multiple nested object initialisers with recursive constructor properties

Is there a way to pass default/constructed property vales in object initializers - to the constructors of nested object initializers? e.g. take these 3 classes Car, Part, Tool Car { public Guid ManufacturerId { get; set; } public Guid CarId {…
0
votes
2 answers

Object initialization in Pythonnet

Let's assume I've the following C# class: public class Test { public double X; public double Y; } I want to use the above C# Test class from IronPython and as well from CPython (using Pythonnet). Using IronPython 2.7 I was able to generate…
Wollmich
  • 1,616
  • 1
  • 18
  • 46
0
votes
1 answer

Use Tuple values in Object initalizer syntax

I'm trying to initialize properties of an object I am creating with the values of a named tuple. Something like this public Person DoIt() { return new Person { (First, Last) = GetFirstAndLast(id) }; } public (string first, string last)…
comecme
  • 6,086
  • 10
  • 39
  • 67