简体   繁体   中英

Can I return an array of different objects from a method in C#

Im creating my own "CMS" in asp.net, I get the page content from the database and then create custom image objects and html content. For example, I have one method called GetPageInformation(string pageName) and it returns a Dictionary of name value pairs, but I want it to return 3 image objects, and 1 string text (with html markup)... is that possible?

Or how can convert this database string value into objects?

(image path ; alt text ; link)
"~/img/home/homeimage.jpg;my alternate text;my href link"

field separator: ';' 
registry separator: '|'

Then I fill one object, just for example:

string[] images = myDBstring.Split('|');

PageImage.Path = images[0].Split(';')[0];
PageImage.AlternateText = images[0].Split(';')[1];
PageImage.LinkUrl = images[0].Split(';')[2];
//...

//PageImage derives from System.Web.UI.WebControls.Image 

Sorry for my bad english... thanks!

You may always return array of objects object[] or dictionary, ie. Dictionary<string, object> . However, I guess it would be better to create classes that meet your needs - ie a class that contains string with html content and array of images.

.Net中的所有类都从Object Class继承,您可以返回一个数组或对象列表

  object[]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM