Renu,
Usage of 'unsafe' and 'fixed' is requried to handle this scenario.
The fixed statement sets a pointer to a managed variable and "pins"
that variable during the execution of statement. Without fixed,
pointers to movable managed variables would be of little use since
garbage collection could relocate the variables unpredictably. The C#
compiler only lets you assign a pointer to a managed variable in a
fixed statement.
Added a small example to help you understand, hope this helps
public class Chainpoint
{
struct Point
{
int _x;
int _y;
public Point(int p,int q)
{
_x = p;
_y = q;
}
public override string ToString()
{
return " x -" + _x.ToString() + " : y -" +
_y.ToString();
}
}
public static void Main()
{
char[] initials = new char[] { 'a', 'c', 'e' };
unsafe
{
/// Example1
fixed (char* p = &initials[0])
{
Console.WriteLine(" First value is ... " +
(char)*p);
};
/// Example2
Point[] coordinates = new Point[]{ new Point(2,2),new
Point(1,1) };
fixed (Point* ptr = &coordinates[1])
{
Console.WriteLine(ptr->ToString());
}
}
}
}
Thanks
Shyam
renu wrote:
hello,
I have one structure named CHAINPOINT,like
CHAINPOINT
{
int x,y;
byte dir
}
I am creating object of CHAINPOINT like
CHAINPOINT* arrayPoint;
arrayPoint = new
CHAINPOINT[arrayChainCode.count];
where arrayChainCode is object of ArrayList.
But its giving error like Cannot implicitly convert type CHAINPOINT[]
to CHAINPOINT*.
If I type cast it 'CHAINPOINT*' then also its giving error.
What can do to solve this problem?
Please suggest me.
Thanking you in advance
Renu