zoukankan      html  css  js  c++  java
  • C#里结构与C/C++结构的区别加疑惑

    C/C++:

    #include "stdio.h"
    struct People
    {
        int age;
        int arr[3];
    };

    void main()
    {
        //printf("%d\n",sizeof(People));
        struct People m={3,{4,5,6}};
        struct People m2=m;
        m2.arr[2]=99;
        printf("%d\n",m.arr[2]);
    }
    

    C#:

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

    namespace 结构
    {
        class Program
        {
            static void Main(string[] args)
            {
                A a;
                a.age = 111;
                a.arr = new int[] { 11, 22, 33 };
                A a2 = a;
                a2.age = 99;
                a2.arr[0] = 66;
                B b = new B();
                b.age = 111;
                b.arr = new int[] { 11, 22, 33 };
                B b2 = b;
                b2.age = 99;
                b2.arr[0] = 66;
                Console.WriteLine(a.age);
                Console.WriteLine(b.age);
                Console.WriteLine("-----------------------------------------------------------------------------");
                Console.WriteLine(a.arr[0]);
                Console.WriteLine(b.arr[0]);
            }
        }
        struct A
        {
            public int age;
            public int[] arr;
        }

        class B
        {
            public int age;
            public int[] arr;
        }
    }

     

  • 相关阅读:
    GB50174-2008《电子信息系统机房设计规范》
    Tickets HDU
    HDU
    [长期更新]题解合集
    网络流/费用流题目总结[持续更新]
    [转载]Maximum Flow: Augmenting Path Algorithms Comparison
    [转载]网络流笔记
    网络流各类算法简单总结与比较
    简单的算法备忘录,个人总结[长期更新]
    训练报告 18春组队04 2014西安全国邀请赛
  • 原文地址:https://www.cnblogs.com/mxw09/p/1834933.html
Copyright © 2011-2022 走看看