实习的时候师傅给写的一个示例

 

using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
namespace test
{
    
class FileNode
    {
        
public string _local;
        
public string _remote;
    }

    
class ServerInf
    {
        
public int _serverid;
        
public ArrayList _filelist;
    }
    
class Program
    {
        
public static ArrayList serverlist;
        
static void AddToList(FileNode node, int id)
        {
            
foreach (ServerInf inf in serverlist)
            {
                
if (inf._serverid == id)
                {
                    inf._filelist.Add(node);
                    
return;
                }
            }

            ServerInf inf1 
= new ServerInf();
            inf1._serverid 
= id;
            inf1._filelist 
= new ArrayList();
            inf1._filelist.Add(node);
            serverlist.Add(inf1);
        }

        
static void Main(string[] args)
        {
            serverlist 
= new ArrayList();

            
for (int j = 1; j < 3; j++)
            {
                
for (int i = 0; i < 5; i++)
                {
                    FileNode node1 
= new FileNode();
                    node1._local 
= "C:\\1.txt" + j + i;
                    node1._remote 
= "\\ctlrpo\\1.7z" + j + i;
                    AddToList(node1, j);
                }
            }
            
foreach (ServerInf inf in serverlist)
            {
                Console.WriteLine(
"server id is " + inf._serverid);
                
foreach (FileNode node in inf._filelist)
                {

                    Console.WriteLine(
"local: " + node._local + ", remote: " + node._remote);
                }
            }


        }
    }
}