I'm pretty sure that I am duplicating a question, but somehow in my example it doesn't work, please see the code:
class Program
{
static void Main(string[] args)
{
Test test1 = new Test("str", "strrr");
}
}
class Test
{
public string testValue, mType;
public Test(string value, string messageType)
{
this.testValue = value;
this.mType = messageType;
}
public Test (string value) : this (value, messageType)
{
//want to manipulate value and messageType here
}
}
messageType in this constructor public Test (string value) : this (value, messageType)
says it doesn't exist in the current context. I want to call it in this way because first of all I want my code instantiating the class with two strings, and then I want to provide value only to one parameter constructor but not lose messageType
, because I will use it within this constructor public Test (string value)
. I read about chaining and instantiating constructors but it seems that this thing is opposite to what I read. Sorry not a lot practice yet with programming if this is a simple question, I would like to know how the code should look. What I have read before pointing this question: Call one constructor from another, How call constructor inside other constructor?, http://www.csharp411.com/constructor-chaining/, it doesn't work for me and again sorry if I am duplicating or doing silly things.