The least-cost way to return a one-row IEnumerable object?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The function must return a IEnumerable object with one row (any data). I have
the following code. Any less cost way?

IEnumerable^ udf()
{
DataTable dt;
dt.Columns->Add("Test");
dt.Rows->Add(1);
return dt.Rows;
}
 
How about

IEnumerable^ udf()
{
return gcnew cli::array<Object^> { yourOneAndOnlyElement };
}
 
nick said:
I am thinking some constant object so there is no runtime gcnew....?

IEnumerable^ is a tracking handle. Tracking handles can only refer to
objects on the garbage collected heap. Objects on the garbage collected heap
are created with gcnew (or boxing, which is not relevant here). So the
answer to your question is: No, there is no way to avoid creating an object
on the gc heap if you want to return IEnumerable^.

Marcus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top