Adrian wrote:
Quote:
What is wrong in the code below?
Adrian.
>
using System;
>
namespace ConsoleApplication2
{
class Trial
{
static void Main(string[] args)
{
MutStruct ms;
ms.partNo = "xxx";
MutTransform mt = new MutTransform(ms.partNo);// errors here "cannot
convert from string to... etc."
Console.WriteLine(mt.PartNumber);
}
}
>
internal struct MutStruct
{
internal string partNo;
}
>
internal struct MutTransform
{
internal string PartNumber;
internal MutTransform(MutStruct mstr)
{
this.PartNumber = mstr.partNo.PadLeft(10, 'y');
}
}
}
Besides the fact that you appear to be using "struct" in an odd way....
The error message you're receiving is correct. ms.PartNo is a string,
but the constructor for MutTransform accepts a MutStruct, not a string.
You should make one of two changes. Either:
MutTransform mt = new MutTransform(ms);
or, down in MutTransform:
internal struct MutTransform
{
internal string PartNumber;
internal MutTransform(string partNo)
{
this.PartNumber = partNo.PadLeft(10, 'y');
}
}
One or the other. By the way, what's the point of wrapping a string in
a struct? Or is this is a pared-down version of what's really going
on...?