470,862 Members | 1,852 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,862 developers. It's quick & easy.

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

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;
}
Apr 19 '06 #1
3 1291
How about

IEnumerable^ udf()
{
return gcnew cli::array<Object^> { yourOneAndOnlyElement };
}
"nick" <ni**@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
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;
}

Apr 19 '06 #2
I am thinking some constant object so there is no runtime gcnew....?

"Marcus Heege" wrote:
How about

IEnumerable^ udf()
{
return gcnew cli::array<Object^> { yourOneAndOnlyElement };
}
"nick" <ni**@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
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;
}


Apr 19 '06 #3

"nick" <ni**@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
I am thinking some constant object so there is no runtime gcnew....?

"Marcus Heege" wrote:
How about

IEnumerable^ udf()
{
return gcnew cli::array<Object^> { yourOneAndOnlyElement };
}


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
Apr 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by venkat | last post: by
8 posts views Thread by Mike Nolan | last post: by
2 posts views Thread by Shawn Minisall | last post: by
2 posts views Thread by laredotornado | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.