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
-2
votes
1 answer

Is there a way to force the type of a property of a VB.Net anonymous type?

I mean something like this (in bold): Dim anonType = New With {.Property1 = 10, .Property2 As Decimal? = Nothing}
kexx
  • 275
  • 5
  • 13
-2
votes
1 answer

Objects re-initalization in c#

Is it considered 'good practice' to re-use objects in c#. For example:       Say you have a class called Anima and create an oject of type animal called monkey: Animal monkey = new Animal(paramA); monkey = new Animal(paramB);
Antoine Dahan
  • 574
  • 2
  • 9
  • 23
-3
votes
3 answers

Loop through Object Initializer

How can I optimize the following piece of code? IList OrderItemsList = new List(); while (orderItemsResult.Read()) { new OrderItem() { ItemName = orderItemsResult.GetString("item_name"), Price =…
scikid
  • 7
  • 4
-3
votes
3 answers

Assign array value inside object initializer in c#

I have a class as below. public class PurgeRecord { public int Index { get; set; } public string Source { get; set; } public int PurgeFileID { get; set; } public string AuthorisationID { get; set; } public string RecordSystem {…
Abhijit
  • 31
  • 1
  • 10
-8
votes
2 answers

How can I create a SIP connecton using Liblinphone interface class?

Want to develop a SIP client for Android using Liblinphone library. There is a LinphoneAuthInfo class that accepts authentication. And a LinphoneCore.addAuthInfo() That adds authentication info to the core. The problem is that I cannot initialize…
rostamiani
  • 2,859
  • 7
  • 38
  • 74
1 2 3
14
15