本文介绍了如何初始化字符数组结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何初始化结构在C#中的字符数组我做这

how to initialize a char array in structure in C# i am doing this

struct cell
{
    public char[] domain =new char[16];
    public int[] Peers;
    public int NumberOfPeers;
    public char assignValue;
}

但它给错误,我们无法初始化数组结构的身体!任何一个可以告诉正确的方法

but its giving error that we cannot initialize an array in the body of structure! can any one tell the correct way

推荐答案

您可以使用的这一点。看MSDN。

You can use a constructor for this. Look at MSDN.

struct cell
{
    public cell(int size)
    {
         domain = new char[size];
         this.Peers = Peers;
         this.NumberOfPeers = NumberOfPeers;
         this.assignValue = assignValue;
    }
}

这篇关于如何初始化字符数组结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 08:53