using System;
class a
{
public int[] data;
public a()
{
data=new int[3];
}
}
class example
{   
static void Main()
{
a[] stack=new a[100];
a temp=new a();
temp.data[0]=1;
temp.data[1]=2;
temp.data[2]=3;
stack[0]=temp;
temp.data[0]=3;
temp.data[1]=2;
temp.data[2]=1;
for(int i=0;i<3;i++)
Console.WriteLine(stack[0].data[i]);//输出为3,2,1 怎样让输出为1,2,3
Console.ReadLine();
}

}

解决方案 »

  1.   

     for(int i=3;i>0;i--)
    {
    Console.WriteLine(stack[0].data[i]);
    }
      

  2.   

    先进后出……什么集合?——“栈”——
    Stack<int> stack =new Stack<int>();
    stack.Push(1);
    stack.Push(2);
    stack.Push(3);
    ..................
    foreach(int i in stack)
    {
    Console.WriteLine(i)...
    }
      

  3.   


        for(int i=temp.data.Length-1;i>-1;i--)
            Console.WriteLine(stack[0].data[i]); //输出为1,2,3
            Console.ReadLine();
        }楼上的都有错,不应该是3,写死的话是i=2;i>-1;i--
      

  4.   

    完全非所问啊 我要将值保存到stack 数组里面去 不能在修改里面的值
      

  5.   

    class a
    {
        public int[] data;
        public a()
        {
            data=new int[3];
        }    public void Reverse()
        {
            Array.Reverse(data);
        }
    }
    class example
    {   
        static void Main()
        {
        a[] stack=new a[100];
        a temp=new a();
        temp.data[0]=1;
        temp.data[1]=2;
        temp.data[2]=3;
        stack[0]=temp;
        temp.data[0]=3;
        temp.data[1]=2;
        temp.data[2]=1;
            stack[0].Reverse();
        for(int i=0;i<3;i++)
            Console.WriteLine(stack[0].data[i]);//输出为3,2,1 怎样让输出为1,2,3
        Console.ReadLine();
        }
        
    }
      

  6.   

    没一个人看懂意思的 
    现在就是说要在stack数组中保存 temp对象
    现在保存的是对象的引用 当修改temp.data[i]时候
    stack里面的stack[0].data[i]也跟着变了
    怎样将temp对象值拷贝一份到stack[0]对象中去 就这个意思
      

  7.   

    class a
    {
        public int[] data;
        public a()
        {
            data=new int[3];
        }    public int[] Reverse()
        {
            int[] temp =new int[data.Length];
            data.CopyTo(temp,0);
            Array.Reverse(temp);
            return temp;
        }
    }
    class example
    {   
        static void Main()
        {
        a[] stack=new a[100];
        a temp=new a();
        temp.data[0]=1;
        temp.data[1]=2;
        temp.data[2]=3;
        stack[0]=temp;
        temp.data[0]=3;
        temp.data[1]=2;
        temp.data[2]=1;
        int[] arr=stack[0].Reverse();
        for(int i=0;i<3;i++)
            Console.WriteLine(arr[i]);//输出为3,2,1 怎样让输出为1,2,3
        Console.ReadLine();
        }
        
    }
      

  8.   

    2楼怎么在1楼的上面,还没3楼,呵呵
    for (int i = 2; i>=0; i--)
                Console.WriteLine(stack[0].data[i]);//输出为3,2,1 怎样让输出为1,2,3
      

  9.   

     using System;
    class a
    {
        public int[] data;
        public a()
        {
            data=new int[3];
        }
    }
    class example
    {   
        static void Main()
        {
        a[] stack=new a[100];
        a temp=new a();
        temp.data[0]=1;
        temp.data[1]=2;
        temp.data[2]=3;
        
        //a.data.CopyTo(stack,0,3); //另一种方式,按照1,2,3次序赋值给stack    for(int i=0;i<3;i++)
             stack[i]=a.data[i];      //按照1,2,3次序赋值给stack         
             //stack[i]=a.data[3-i];  //按照3,2,1次序赋值给stack
        }
        
    }
      

  10.   

    自己找了答案 哎 ~
    象楼上的还在回复
    C#中有两种类型变量,一种是值类型变量,一种是引用类型变量。对于前者,copy是属于全盘复制;而对于后者,一般的copy只是浅copy,相当于只传递一个引用指针一样。因此对于后者进行真正copy的时候,也是最费事的,具体的说,必须为其实现ICloneable接口中提供的Clone方法。浅拷贝(影子克隆):只复制对象的基本类型,对象类型,仍属于原来的引用.
    深拷贝(深度克隆):不紧复制对象的基本类,同时也复制原对象中的对象.就是说完全是新对象产生的public class Test
    {    
        public class Person : ICloneable
         {
            public int ID;
            public int age;
            public void Show()
             {
                 Console.WriteLine("ID:{0} 年龄:{1}",ID, age);
             }
            public object Clone()
             {
                 Person newPerson = new Person();
                 newPerson.ID = this.ID;
                 newPerson.age = this.age;      
                return newPerson;
             }
         }
        public static void ShowPersons(Person[] persons)
         {
            for (int i=0; i<persons.GetLength(0); i++)
             {
                 persons[i].Show();
             }
         }
        static void Main(string[] argv)
         {
             Random rnd = new Random(unchecked((int)DateTime.Now.Ticks));
             Person[] persons = new Person[4];
            for (int i=0;i<persons.GetLength(0);i++)
             {
                 persons[i] = new Person();
                 persons[i].ID = rnd.Next()%10;
                 persons[i].age = rnd.Next()%50;
             }
            //打印原始数组
             Console.WriteLine("打印原始数组");
             ShowPersons(persons);
            //深拷贝
             Person[] personsCopied = new Person[4];
            for (int i=0;i<personsCopied.GetLength(0);i++)
             {
                 personsCopied[i] = (Person)persons[i].Clone();
             }
            //persons.CopyTo(personsCopied, 0);
             Console.WriteLine("深拷贝的数组");
             ShowPersons(personsCopied);
    //      //浅拷贝
    //       Person[] personsCloned = (Person[])persons.Clone();
    //       Console.WriteLine("浅拷贝的数组");
    //       ShowPersons(personsCloned);
            //对原数组做修改
             persons[2].ID += 10;
             Console.WriteLine("打印修改后的原始数组");
             ShowPersons(persons);
             Console.WriteLine("深拷贝的数组应该不改变");
             ShowPersons(personsCopied);
    //       Console.WriteLine("浅拷贝的数组应该改变");
    //       ShowPersons(personsCloned);
         }
    }
      

  11.   

    不好意思,上面搞错了using System;
    class a
    {
        public int[] data;
        public a()
        {
            data=new int[3];
        }
    }
    class example
    {   
        static void Main()
        {
        a[] stack=new a[100];
        
        a temp=new a();
        temp.data[0]=1;
        temp.data[1]=2;
        temp.data[2]=3;
        
        stack[0] = new a();
        temp.data.CopyTo(stack[0].data,0,3);
    }
      

  12.   

    using System;
    class a
    {
        public int[] data;
        public a()
        {
            data=new int[3];
        }
    }
    class example
    {   
        static void Main()
        {
        a[] stack=new a[100];
        a temp=new a();
        temp.data[0]=1;
        temp.data[1]=2;
        temp.data[2]=3;
        stack[0]=temp;
        temp.data[0]=3;
        temp.data[1]=2;
        temp.data[2]=1;
        for(int i=2;i>=0;i--)
            Console.WriteLine(stack[0].data[i]);//输出为1,2,3
        Console.ReadLine();
        }
        
    }
      

  13.   


    正规的做法,如果你是想让类可以克隆,那就推荐实现克隆接口。如果只是简单的类,没有太多的属性,也可以采取属性赋值的方法。如果要克隆的类是无法修改的,不受你控制的,例如系统类,其他人写的类,可以使用反射获取属性赋值。如果克隆的情形有时候并非完整的,即有条件策略的,或者此类不想影响子类,强制子类也实现克隆接口,则可以采取设计模式中的Prototype(原型),在专属的一个服务类中处理此事。无论如何做,都是按照需求来的,看你自己的需求来决定。但对于引用类型和值类型的区别,内存管理方式,一定要深入掌握。另外,建议您下次提问时,一开始就说清楚你的真实意图。看这个贴中多少人被你的提问误导了……
      

  14.   

    int 数组  然后加排序输出
      

  15.   

    用一个最傻的方法
        class a 
    {
            public int[] data;
            public a()
            {
                data = new int[3]; 
            }
        public a(a olda) 
        { 
            data=new int[3]; 
            Array.Copy(olda.data,data,data.Length);
        } a[] stack=new a[100];
        a temp=new a();
        temp.data[0]=1;
        temp.data[1]=2;
        temp.data[2]=3;
        stack[0]=new a(temp);
        temp.data[0]=3;
        temp.data[1]=2;
        temp.data[2]=1;
        for(int i=0;i<3;i++)
            Console.WriteLine(stack[0].data[i]);//输出为1,2,3
        Console.ReadLine();
      

  16.   

    [Quote=引用 4 楼 yingmu 的回复:]
    引用 1 楼 jijunwu 的回复:
    for(int i=3;i>0;i--) 

    Console.WriteLine(stack[0].data[i]); 

      

  17.   

    应该是这个
    for(int i=3;i>0;i--)
    {
       ......
    }
      

  18.   

    for(int i=3;i>0;i--) 

    Console.WriteLine(stack[0].data[i]); 
    }
      

  19.   

     using System;
    class a
    {
        public int[] data;
        public a()
        {
            data=new int[3];
        }
    }
    class example
    {   
        static void Main()
        {
        a[] stack=new a[100];
        a temp=new a();
        temp.data[0]=1;
        temp.data[1]=2;
        temp.data[2]=3;
        stack[0]=temp;
        temp.data[0]=3;
        temp.data[1]=2;
        temp.data[2]=1;
        for(int i=0;i<3;i++)
        {
            for(int j=+1;i<3;i++)
            {
              if(stack[i]>stack[j])
              {
                 int temp2=stack[i];
                 stack[i]=stack[j];
                 stack[j]=temp2;
              }
            }
      //      Console.WriteLine(stack[0].data[i]);//输出为3,2,1 怎样让输出为1,2,3
        //    Console.ReadLine();
        }
        for(int n=0;n<3;n++)
        {
            Console.WriteLine(stack[n]);
        }
        Console.ReadLine();
        }
        
    }
      

  20.   

     using System;
    class a
    {
        public int[] data;
        public a()
        {
            data=new int[3];
        }
    }
    class example
    {   
        static void Main()
        {
        a[] stack=new a[100];
        a temp=new a();
        temp.data[0]=1;
        temp.data[1]=2;
        temp.data[2]=3;
        stack[0]=temp;
        temp=new a();
        temp.data[0]=3;
        temp.data[1]=2;
        temp.data[2]=1;
        for(int i=0;i<3;i++)
            Console.WriteLine(stack[0].data[i]);//输出为3,2,1 怎样让输出为1,2,3
        Console.ReadLine();
        }
        
    }