public class PhotoList : ObservableCollection<ImageFile>
{
public PhotoList() { }
**//this is the line that I dont recognise!!!!!!!!!!**
public PhotoList(string path) : this(new DirectoryInfo(path)) { }
public PhotoList(DirectoryInfo directory)
{
_directory = directory;
Update();
}
public...
In the following code:
public class A
{
public A():this(null){}
public A(string b){/*code here*/}
}
What is the use of first constructor?
...
Hi all, I know that this is supposedly a super simple question, but I've been struggling with the concept for some time now. My question is, how do you chain constructors in c#? I'm in my first OOP class, so I'm just learning. I don't understand how constructor chaining works or how to implement it, or even why it's better than just do...
Hi, I'm just getting the concept of chaining constructors down, but I can't figure out how to chain these two particular constructors together, so I would appreciate it if somebody could help me out.
Thanks!
Constructors
// default constructor
// purpose: initialize data members to zero
// Parameters: none
// returns: none
public Li...
Hello there,
I'm in my first OOP class and I really like it, but on this assignment, I'm not really sure what the best (most efficient, less code, etc.) way to use constructors in this situation? Preferably using constructor chaining.
A little more info:
I would like my default constructor to create & initialize all the objects shown...
Hi,
I have an assignment for my first OOP class, and I understand all of it including the following statement:
You should create a class called ComplexNumber. This class will contain the real and imaginary parts of the complex number in private data members defined as doubles. Your class should contain a constructor that allows the...
Original Question
Consider the following scenario:
public abstract class Foo
{
public string Name { get; set; }
public Foo()
{
this.Name = string.Empty;
}
public Foo(string name)
{
this.Name = name;
}
}
public class Bar : Foo
{
public int Amount { get; set; }
public Bar()
:...
In C# when I want to chain constructors together I'd do this...
public class OperationMacro : GeneratePropertyMacro {
public OperationMacro() : base("Operation") {
//Whatever else I need to do...
}
}
What is the equivalent syntax in Boo?
...
My motivation for chaining my class constructors here is so that I have a default constructor for mainstream use by my application and a second that allows me to inject a mock and a stub.
It just seems a bit ugly 'new'-ing things in the ":this(...)" call and counter-intuitive calling a parametrized constructor from a default construct...
Hi I've been playing around trying to recreate the way in which jQuery chains it's functions for it's "select" then "do" behaviour.
Note: I don't want to chain functions with jQuery, I want to chain them like jQuery.
So based on the jQuery code what I have so far is (doesn't work in IE):
var x = function(string) {
return new x.fn....
I'm trying to get a better understanding of general practice... specifically deriving this() in a constructor. I understand that its less code, but I consider it less readable. Is it common/good practice to do it this way? Or is it better to write a second constructor that handles it specifically?
public SomeOtherStuff(string rabble)...
Update: gutted the question with a simpler example, that isn't answered
by the originally accepted answer
Given the following class, and its ancestor:
TComputer = class(TObject)
public
constructor Create(Teapot: string='');
end;
TCellPhone = class(TComputer)
public
constructor Create(Cup: Integer); overload; virtual;
co...
i'm looking to understand
virtual
override
overload
reintroduce
when applied to object constructors. Every time i randomly add keywords until the compiler shuts up - and (after 12 years of developing with Delphi) i'd rather know what i'm doing, rather than trying things randomly.
Given a hypothetical set of objects:
TComputer = cla...
Update: The example i originally had was kind of complex. Here's a simple 8 line example that explains everything in one code block. The following does not compile gives a warning:
TComputer = class(TObject)
public
constructor Create(Cup: Integer); virtual;
end;
TCellPhone = class(TComputer)
public
constructor Create(Cup: Integ...
Today Recently on Stackoverflow i learned that:
reintroduce is used to hide ancestor constructors
reintroduce is used to show ancestor constructors
i've been trying to make sense of it all, so here is a another, very specific question, supporting my main question dealing with constructors.
Update: replaced the entire question:
TC...
Yet another in my series of questions regarding constructors in Delphi.
i have a base class that has has the virtual constructor:
TComputer = class(TObject)
public
constructor Create(Teapot: Integer); virtual;
end;
The constructor is virtual for the times that someone needs to call
var
computerClass: class of TComputer;
co...
Here's two simple classes, initially both have no keywords (virtual, overload, override, reintroduce):
TComputer = class(TObject)
public
constructor Create(Teapot: Integer);
end;
TCellPhone = class(TComputer)
public
constructor Create(Teapot: Integer; Handle: string);
end;
i will represent these above defintions as the slightly...
Hello!
I'm trying to implement some kind of class hierarchy in JavaScript. I
think I understood the prototype chain, but I still have to sort out the
constructor-chaining. Following David Flanagan's Definitive Guide,
I wrote
function DerivedClass()
{
BaseClass.apply(this, arguments); // chain constructors
// do some initializa...