本文介绍了从程序返回列表(新手)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我是C#的新手
我还不了解所有事物如何相互连接,例如类和对象...

我创建了一个简单的项目.
我的目标是拥有两个不同的公共班级.

myfirst类(包含并列出"companyInfo")

mySecondClass(调用companyinfo列表)

从静态void Main(string [] args)中警报companyInfo中的所有项目

有人可以帮我吗?

请参阅下面的代码:

Hello People,

I am total new to C#
I haven''t understood how everything is connected to each other classes and objects etc...

I have created a a simple project.
My goal it is to have two different public classes.

myfirst class(contains and list "companyInfo")

mySecondClass (calls the companyinfo list)

from static void Main(string[]args) alert all items in the companyInfo

Could someone help me?

see my code below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace MyProgram
{
     }
     class Program
    {
        static void Main(string[] args)
        {
            {

                CompanyMain CCinfo = new CompanyMain();         
           
            }
        }


        public class myList
        {
            static List<string> CompanyInfo()
            {
                List<string> CompanyInformation = new List<string>();
                CompanyInformation.Add("test1");
                return CompanyInformation;
            }
        }

        public class CompanyMain
        {

            myList CompanyInfo = new myList();
            
        }

     }



在此先谢谢您



Thank you in advance

推荐答案

public class CompanyMain
        {
 
           public myList Company<big></big>Info = new myList();
            
        }




之后,主要可以看到CompanyInfo字段,并且可以对其进行操作.




After that, in the main you can see the CompanyInfo field and you can manipulate it.

static void Main(string[] args)
       {
           {
               CompanyMain CCinfo = new CompanyMain();
           foreach(var item = CCinfo.CompanyInfo.CompanyInfo()){
                 //

             }
           }
       }


foreach s in CCinfo.CompanyInfo()
 ''do something with the company info here...
next


这篇关于从程序返回列表(新手)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 09:19