inheritence

D

DaveP

hello...
I wrote a Base class to dealer with Text Files
i want to inherit this class to extend its functionality

i want to inherit a class. But before i send parameters to the Base/parent
class
i want to make some default parameters

looking for examples somthing like below

public class Abase
{
public A(FileInfo Filename,object[,]])
{
//do something
}
}
public class Achild
{
public Achild(Fileinfo filename)
{
//here i want to define Astru then Call Base Class

}
}
 
T

tsahiasher

hello...
I wrote a Base class to dealer with Text Files
i want to inherit this class to extend its functionality

i want to inherit a class. But before i send parameters to the Base/parent
class
i want to make some default parameters

looking for examples somthing like below

public class Abase
{
public A(FileInfo Filename,object[,]])
{
//do something
}}

public class Achild
{
public Achild(Fileinfo filename)
{
//here i want to define Astru then Call Base Class

}





}

you can't. base() must be called before you enter the child class
constructor.
 
D

DaveP

thats what i thought
Thanks
DaveP
hello...
I wrote a Base class to dealer with Text Files
i want to inherit this class to extend its functionality

i want to inherit a class. But before i send parameters to the
Base/parent
class
i want to make some default parameters

looking for examples somthing like below

public class Abase
{
public A(FileInfo Filename,object[,]])
{
//do something
}}

public class Achild
{
public Achild(Fileinfo filename)
{
//here i want to define Astru then Call Base Class

}





}

you can't. base() must be called before you enter the child class
constructor.
 
B

Bjorn Abelli

DaveP said:
I wrote a Base class to dealer with Text Files
i want to inherit this class to extend its functionality

i want to inherit a class. But before i send parameters to
the Base/parent class
i want to make some default parameters

===========================================================
If you really mean "default" parameters, it's very easy, e.g.:

public class A
{
public A(string a, string b)
{
Console.WriteLine("a:" + a + ", b:" + b);
}
}

public class B : A
{
public B(string a) : base(a, "my default value")
{

}
}

===========================================================

If you need something more complex, there are some options, but I find an
easy one to make a static method, e.g.:

public class A
{
public A(string a, string b)
{
Console.WriteLine("a:" + a + ", b:" + b);
}
}

public class B : A
{
public B(string a) : base(a, Init(a))
{

}

static string Init(string a)
{
return "my default value and " + a.ToUpper();
}
}

===========================================================

/// Bjorn A
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top