i want to call base and this constructor at the same time. is is possible?
i mean:
B(int a, int b, int c):base(a):this(b)
{
// do something with c
}
at java i used to do that:
B(int a, int b, int c)
{
super (a);
this(b);
// do something with c
}
and if yes, how is its syntax.
thanks in advance
alpos 4 2447
Murat,
No, this is not possible. If you want to call the this and base
constructor, then you will have to call "this" constructor which in turn
calls the "base" constructor (in a chain).
In your case, you would have to have B(int, int, int) call B(int) which
in turn would call base(int).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"murat oguzalp" <murat_oguzlap> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... i want to call base and this constructor at the same time. is is possible?
i mean: B(int a, int b, int c):base(a):this(b) { // do something with c }
at java i used to do that:
B(int a, int b, int c) { super (a); this(b); // do something with c }
and if yes, how is its syntax.
thanks in advance
alpos
Rakesh,
This is not possible, as you need to indicate whether or not you call
"this" or "base" before any code in the constructor is run.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com... I don't know if i got ur question right. But you could use the base keyword for this operation.
Eg: B(int a, int b, int c) { base(a); this.<constructor>(b); // do something with c }
"murat oguzalp" wrote:
i want to call base and this constructor at the same time. is is possible?
i mean: B(int a, int b, int c):base(a):this(b) { // do something with c }
at java i used to do that:
B(int a, int b, int c) { super (a); this(b); // do something with c }
and if yes, how is its syntax.
thanks in advance
alpos
"murat oguzalp" <murat_oguzlap> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... i want to call base and this constructor at the same time. is is possible?
i mean: B(int a, int b, int c):base(a):this(b) { // do something with c }
at java i used to do that:
B(int a, int b, int c) { super (a); this(b); // do something with c }
No you didn't; that is not legal java.
In Java, you'd do something like:
B(int a, int b, int c)
{
super(a);
init(b);
}
B(int b)
{
init(b);
}
private init(int b)
{
... common init logic
}
In C#, you do the same.
thaks to everyone for sharing information.
Mike is right. i thought, i could have done it.
but neither java, it's not legitimate
alpos
"Mike Schilling" <ms*************@hotmail.com> wrote in message
news:eN**************@TK2MSFTNGP12.phx.gbl... "murat oguzalp" <murat_oguzlap> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...i want to call base and this constructor at the same time. is is
possible? i mean: B(int a, int b, int c):base(a):this(b) { // do something with c }
at java i used to do that:
B(int a, int b, int c) { super (a); this(b); // do something with c }
No you didn't; that is not legal java.
In Java, you'd do something like:
B(int a, int b, int c) { super(a); init(b); }
B(int b) { init(b); }
private init(int b) { ... common init logic }
In C#, you do the same.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Giulio |
last post by:
why definition of two constructors like these is not possible in c++???
-----------------------
date::date(const int d, const int m, const int y, const int ora, const int
mi, const int se){...
|
by: William Payne |
last post by:
Hello, consider these following two classes. A base class, class
MDIChildWindow, and a class inherting from that base class, class Document.
In the static base member function callback() I obtain a...
|
by: Justin |
last post by:
Hello, first time posting.
If I have a base class and a derived class, is there only one way to
call the base constructor?
i.e. Is this the only way I can call the base constructor...
|
by: Jo Vermeulen |
last post by:
Hello,
I was wondering how I could call the base class constructor from a derived
class constructor. In Java I could do something like
super(parameter);
I tried
base(parameter);
|
by: Josef Meile |
last post by:
Hi,
I have this constructor:
public CExcelDatabase(string host, string user, string password, string
database,
bool promptCredentials, int
findExcelInstance, bool readOnly)
{
//Some code...
|
by: Sathyaish |
last post by:
How does a constructor of one class call another of the same class?
When would this mechanism make sense or be required?
PS: Two instances I saw are:
(a) While using the Singleton pattern...
|
by: st_ev_fe |
last post by:
I've noticed that when constructing a subclass, the base class get's
it's contructors called.
Is there some way to avoid this? The base class has one variable, which
gets initialised to 0.
...
|
by: ypjofficial |
last post by:
Hello All,
So far I have been reading that in case of a polymorphic class ( having
at least one virtual function in it), the virtual function call get
resolved at run time and during that the...
|
by: jan.loucka |
last post by:
Hi,
We're building a mapping application and inside we're using open
source dll called MapServer. This dll uses object model that has quite
a few classes. In our app we however need to little bit...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| | |