Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
class AttachToObjectData : IData

I have this two list
m_attachObjectDataListToProcess = new List<attachtoobjectdata>();
createAndCheckInObjectDataList = new List<idata>();

i have one function where i want to give IData as input.

so for that i want to convert List<attachtoobjectdata> to List<idata>


for example : updateDocument(IData)

now for this call i want data should be in IData

Regars
Bhushan

What I have tried:

I tried
m_attachObjectDataListToProcess.Convert : Not working
m_attachObjectDataListToProcess
.Cast : Not working
Posted
Updated 16-Aug-17 3:44am
v2
Comments
Richard Deeming 17-Aug-17 10:35am    

Change the definition of m_attachObjectDataListToProcess to:
C#
m_attachObjectDataListToProcess = new List<idata>();

Then you can add AttachToObjectData objects to m_attachObjectDataListToProcess as AttachToObjectData implements idata interface. now you can do what you are trying to do.
 
Share this answer
 
If you have an interface like this
public interface IData
{
    string Value { get; set; }
}

and a class implementing this interface
public class Data : IData
{
    public string Value { get; set; }
}

and a list of Data like this
var dataList = new List<Data>
{
    new Data {Value = "A"},
    new Data {Value = "B"}
};

you could cast to IData like this:
var iDataList = dataList.Cast<IData>();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900