Linked Questions

12 votes
10 answers
9k views

Possible Duplicate: Initialize class fields in constructor or at declaration? We are arguing about coding practices. The examples here are a little too simple, but the real deal has several ...
John Nicholas's user avatar
13 votes
6 answers
29k views

Possible Duplicate: Best Practice: Initialize class fields in constructor or at declaration? Most of the time, I see the way of initializing a variable like this public class Test { private ...
System.Data's user avatar
  • 3,988
9 votes
9 answers
2k views

I worked with a developer that had many years my senior in C# experience. I no longer have a way to contact him and I remember him saying that it's not a good idea to include code in a default ...
broguyman's user avatar
  • 1,426
5 votes
4 answers
10k views

As we know, in java and some other object-oriented programming languages, fields value can be set in constructor or be initialized in fields declaration statements. I want to know the essential ...
Cao Dongping's user avatar
4 votes
5 answers
6k views

What is the difference between the following two, and which is more preferable?? public class foo { int i = 2; } public class foo { int i; foo() { i = 2; } }
user1976547's user avatar
4 votes
4 answers
7k views

Possible Duplicate: Best Practice: Initialize class fields in constructor or at declaration? I am working with C# but this probably applies to Java (or any other language that allows this behavior ...
DigitalZebra's user avatar
  • 41.9k
1 vote
1 answer
2k views

I'm trying to understand the difference in variable declaration of a class inside or outside of a constructor. In this case creating the list for grades. To me, the below achieves the same result so ...
Aiden's user avatar
  • 311
3 votes
6 answers
133 views

What is the difference between the following code fragments? Form1 form1 = new Form1(); and Form1 form1; public Class1() { form1 = new Form1(); }
Etrit's user avatar
  • 915
0 votes
4 answers
1k views

Possible Duplicate: Best Practice: Initialize class fields in constructor or at declaration? this is just a simple and even a little stupid doubt that me and my friends raised while talking about our ...
EngFabioDario's user avatar
4 votes
2 answers
128 views

I am beginner in object oriented programming and I have one simple question. What is difference between: public class Calculation { private _externalObject = new ExternalClass(); public ...
user1955466's user avatar
1 vote
2 answers
1k views

Possible Duplicate: Best Practice: Initialize class fields in constructor or at declaration? Is there any difference between these two classes? public class Test { public Guid objectId = Guid....
William's user avatar
  • 1,487
1 vote
2 answers
155 views

I'm currently working through some old code and I started to wonder, is there actually any difference between: public class XmlExport : IXmlExport { private readonly IJobRepository jobRepository ...
Lobsterpants's user avatar
  • 1,258
3 votes
2 answers
164 views

Possible Duplicate: Best Practice: Initialize class fields in constructor or at declaration? Please do you have any advantage for doing public class MyClass { List<string> list; public ...
David Blay's user avatar
0 votes
1 answer
161 views

In what scenario would you initialise class variables in constructors and when without constructor? class CustomList { public Node head; public int count; public ...
Yugraaj Sandhu's user avatar
0 votes
3 answers
112 views

Is there any practical difference between those two ways of instantiating an object? public class myClass { private myType myObject = new myType(); } and public class myClass { private myType ...
Richard77's user avatar
  • 21.9k

15 30 50 per page