如何在另一个班级中呼叫列表

如何在另一个班级中呼叫列表

本文介绍了如何在另一个班级中呼叫列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。我在两个班级之间遇到这个问题。在第1类中,有一个值作为列表。我想用console.writeline在第二类ta中打印此列表。在这种情况下,如何在另一个类和打印列表中调用列表值。 />


Definition.cs

Hello.I'm having this problem between two classes. In the 1st class, there is a value as a list.I would like to print this list in the 2nd class ta with console.writeline.In this case, how can I call the list value in another class and print list.

Definition.cs

public List<string> ListValue=new List<string> ();



Usebility.cs(通话类)



我尝试过:




Usebility.cs (call class)

What I have tried:

Console.WriteLine( ListValue);

推荐答案

foreach(string s in ListValue)
    Console.WriteLine(s);


ing System;
using System.Collections.Generic;

namespace classSample
{
    class Program
    {
        static void Main(string[] args)
        {
            ClassTwo cTwo = new ClassTwo();
            List<string> theList = cTwo.GotThem;
            foreach (string item in theList)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("Hello World!");
            Console.ReadKey();
        }
    }
    public class ClassOne
    {
        public List<string> GetMe = new List<string>();

        public ClassOne()
        {
            GetMe.Add("one");
            GetMe.Add("two");
            GetMe.Add("three");
        }

    }
    public class ClassTwo
    {
        public List<string> GotThem { get; set; }

        public ClassTwo()
        {
            ClassOne cOne = new ClassOne();
            GotThem = cOne.GetMe;
        }
    }
}


这篇关于如何在另一个班级中呼叫列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:12