2

私の問題は、別のクラスに接続された List<> 変数があり、その List<> からすべての項目を取得して文字列に入れたいことです。

結果の文字列で、callNum、copyNum、content、author、year、title を確認したい

これが私がそれを文字列に入れようとしているところです

public class CItemControl
    {
        //declare a list variable
        private List<CItem> mItems;
        private CItem mNewItem;
        //a method that instantiates the list
        public CItemControl()
        {
            mItems = new List<CItem>();
        }
        //attribute to get all items
        public List<CItem> Items
        {
            get { return mItems; }
        }
        public CItem NewItem
        {
            get { return mNewItem; }
        }
        //method to add item to the CItem list
        public void AddItem(int callNum, int copyNum, string content, string author, string year)
        {
            mNewItem = new CItem(callNum, copyNum, content, author, year);
            mItems.Add(mNewItem);
        }
        //method to return all items to a string
        public CItem ListAllItems()
        {
            string allItems;


        }

これは、アイテムを取得しようとしているクラスです。後で変数が追加されます。

class CItem
    {
        //declare attributes
        private string mTitle;
        private string mAuthor;
        private string mContent;
        private string mYear;
        private int mCopyNum;
        private int mCallNum;
        private bool mHold = false;
        private bool mBorrowed = false;
        private bool mShelf = false;

        //overload a constructor
        public CItem(int CallNum, int CopyNum, string Content, string Author, string Year)
        {
            callNum = CallNum;
            copyNum = CopyNum;
            content = Content;
            author = Author;
            year = Year;
        }

        //create the default constructor
        public CItem()
        {
            callNum = 0;
            copyNum = 0;
            content = "";
            author = "";
            year = "";
        }

        //set attributes
        public int callNum
        {
            get { return mCallNum; }
            set { mCallNum = value; }
        }
        public string content
        {
            get { return mContent; }
            set { mContent = value; }
        }
        public string author
        {
            get { return mAuthor; }
            set { mAuthor = value; }
        }
        public string year
        {
            get { return mYear; }
            set { mYear = value; }
        }
        public string title
        {
            get { return mTitle; }
            set { mTitle = value; }
        }
        public int copyNum
        {
            get { return mCopyNum; }
            set { mCopyNum = value; }
        }
        public bool hold
        {
            get { return mHold; }
        }
        public bool borrowed
        {
            get { return mBorrowed; }
        }
        public bool shelf
        {
            get { return mShelf; }
        }

        //display information for users
        public string displayInfo()
        {
            return "Call Number: " + callNum + ". Copy Number: " + copyNum + ". Title: " + title +
                ". Author: " + author + ". Year Published: " + year + ". Content: " + content;
        }

        //new method to display status of item
        public string displayStatus()
        {
            if (borrowed == true)
                return "Item is currently being borrowed.";
            if (shelf == true && hold == false)
                return "Item is available for borrowing.";
            else
                return "Item is on hold";
        }

どんな助けでも大歓迎です!前もって感謝します。

4

4 に答える 4

1
return String.Join("; ", allItems.Select(item => item.displayInfo()));
于 2013-04-20T17:58:40.267 に答える