Problems In Visual C# coding




Sir,
I have a certain part of code which i have changed to visaul C# from c++ it is giving me some problems.I am not able to understand how to solve it.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Image *createILNode(char* filename)
{
ImageList *node = new imageList();
node->imageIndex = 0;
node->next subject = null;
node->next_replicate = null;
return node;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Public struct ImageList
{
unsafe public char[] filename;
public int imageIndex;
unsafe public ImageList *next_replicate;
unsafe public ImageList *next_subject;
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
These lines are giving me problem.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ImageList subject;
subject = header = createILNode(token);
subject.next_subject = createILNode(token);
subject = subject.next_subject;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
the problem i am facing is that the assignment in above part of code is not working.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1. Cannot Take the address or the size of the variable of managed type ('structure_test.ImageList').

}

[2064 byte] By [Naveenkoul] at [2008-2-18]
# 1

You should never do the assignment this way, I would appreciate if you better make this thing as a class overload = opeartor and make a copy conmstructor. Only this way you will be able to do correct object assignment. In your case it is performing shallow assignments.

Moreover

The sizeof operator can be applied only to value types, not reference types.

The sizeof operator can only be used in the unsafe mode.

The sizeof operator cannot be overloaded.

See MSDN article

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfsizeofpg.asp for an in depth view

Heres a small piece of code, how to write a linklist in C#. Hopefully this will help you out Smile

using System;

namespace AfterBurner{

class LinkList{

public string Val;
public object NextItem;


[STAThread]
static void Main(string[] args)
{
LinkList obList = new LinkList();
obList.Val = "Head";

LinkList obHead = obList;

// Add 10 items to the list.
for (int i = 0; i < 10; i++)
{
obList.NextItem = new LinkList();
obList = (LinkList)obList.NextItem;
obList.Val = i.ToString();
}

// Print the added items.
while (obHead != null)
{
Console.WriteLine("Item: {0}", obHead.Val);
obHead = (LinkList)obHead.NextItem;
}
}
}

}
Best's

AfterBurner
MCP

AfterBurner at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...