Is there any way to automatically create the constructor for a class based on the properties in the class like Eclipse does? (Without getting ReSharper). I'm using Visual Studio 2008 (C#).
If this is a duplicate, please link (I tried searching).
Is there any way to automatically create the constructor for a class based on the properties in the class like Eclipse does? (Without getting ReSharper). I'm using Visual Studio 2008 (C#).
If this is a duplicate, please link (I tried searching).
No. There is the ctor snippet(not quite what you were looking for), or you can create your macro. Possibly check out Productivity macros for C#. And since you don't like ReSharper, you can use CodeRush.
you can use object initializer
instead of having created a constructor, if you're using C# 3.0.
Referring code that I found in some example.
class Program
{
public class Student
{
public string firstName;
public string lastName;
}
public class ScienceClass
{
public Student Student1, Student2, Student3;
}
static void Main(string[] args)
{
var student1 = new Student{firstName = "Bruce",
lastName = "Willis"};
var student2 = new Student{firstName = "George",
lastName = "Clooney"};
var student3 = new Student{firstName = "James",
lastName = "Cameron"};
var sClass = new ScienceClass{Student1 = student1,
Student2 = student2,
Student3 = student3};
}
}