bloggerads

2015年12月30日 星期三

C# : The difference between C# and C in initializing a struct array

The difference between  C# and C in initializing a struct array

// C#
struct st
{
    public int x;
    public int y;
} 
public static void Main(string[] args)
{
    st [] o = new st [] {
        new st { x=2, y=3 },
        new st { x=3, y=4 }
    };
}

// C/C++
struct st
{
    int x;
    int y;
};

int main()
{
    st o[] = {
        {.x=2, .y=3},
        {.x=3, .y=4}
    };
}

沒有留言:

張貼留言