|
| |||||||||
| Tags: c sharp, constructor, csharp, programming code |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| One constructor to call another in C Sharp
I have begin to learn C sharp since last month. I have studied HTML and MS-SQL earlier but nothing as such in software programming language. For this reason I am finding learning C sharp very difficult. I have a doubt in Constructor topic. My doubt is can one constructor call another? Please illustrate with an example if possible. |
|
#2
| |||
| |||
| Re: One constructor to call another in C Sharp
The solution to your doubt is that, Yes in C-Sharp one constructor can call another. The following code will show how to call one constructor from another constructor. Code: public class Top : Stud
{
public Top (int holiday) : base (holiday)
{
.
.
.
}
} Last edited by Katty : 21-11-2009 at 02:36 AM. |
|
#3
| ||||
| ||||
| Re: One constructor to call another in C Sharp Code: public class mySampleClass
{
public Test(): this(10)
{
// parameterless constructor
}
public Test(int Age)
{
// constructor with single parameter
}
} Code: : this (parameters)
__________________ The FIFA Manager 2009 PC Game Last edited by opaper : 21-11-2009 at 02:25 AM. |
|
#4
| ||||
| ||||
| Re: One constructor to call another in C Sharp
Here is a very simple example to illustrate how one constructor can call another in Csharp programming language. Let us assume the following code see where we have to call the seond constructor, Code: public class Abc
{
public Abc ()
{
// to call the second constructor here
}
public Abc (int n1, int n2, int n3)
{
// some code
}
} Code: public Abc (int param1, int param2, int param3) : base(param1, param2, param3) |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "One constructor to call another in C Sharp" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Call entry stuck in Nokia C3-00 call log and stopped call logging | Elijah*Blue | Portable Devices | 13 | 21-10-2011 08:49 PM |
| Sharp 007SH Hybrid An 3D Clamshell Android Phone by Sharp | jackalz | Web News & Trends | 3 | 22-05-2011 08:28 AM |
| What is the use of private constructor in C++? | Juaquine | Software Development | 5 | 05-03-2010 04:41 PM |
| copy constructor Vs constructor | Truster | Software Development | 5 | 08-02-2010 02:49 PM |
| Array of Objects to call constructor | KALLIYAN | Software Development | 3 | 04-11-2009 09:54 PM |