TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Michael Hervas
NA
8
18k
Converting Object Properties to Array
Jan 31 2021 12:43 AM
public
class
myObj
{
public
string
ob1 {
get
;
set
; }
public
string
ob2 {
get
;
set
; }
}
List<myObj> objlist =
new
List<myObj>();
objlist.Add(
new
myObj
{
ob1 =
"A"
,
ob2 =
"1"
});
objlist.Add(
new
myObj
{
ob1 =
"B"
,
ob2 =
"2"
});
List<
string
[]> converted = MyConvert(objlist);
public
static
List<
string
[]> MyConvert(List<objlist> mobj)
{
foreach
(objlist item
in
mobj)
{
string
[] arr = ((IEnumerable)item).Cast<objlist>()
.Select(x => x.ToString())
.ToArray();
}
}
I've been trying to convert the object objlist to a List of string array. I've searched the net and found IEnumerable might help, but I got stopped by an error when I run the program..
System.InvalidCastException
HResult=0x80004002
Message=Unable to cast object of type 'objlist' to type 'System.Collections.IEnumerable'.
Reply
Answers (
5
)
How to read mastercard ipm file in c#.please can any body tell me?
Error while 32-bit C# program calling 32-bit C++ DLL