Click here to Skip to main content
15,888,521 members
Home / Discussions / C#
   

C#

 
GeneralRe: Manual Coding vs Code Generation Pin
Phanindra26116-Nov-12 7:56
Phanindra26116-Nov-12 7:56 
GeneralRe: Manual Coding vs Code Generation Pin
fjdiewornncalwe16-Nov-12 8:26
professionalfjdiewornncalwe16-Nov-12 8:26 
AnswerRe: Manual Coding vs Code Generation Pin
Mycroft Holmes16-Nov-12 15:37
professionalMycroft Holmes16-Nov-12 15:37 
GeneralRe: Manual Coding vs Code Generation Pin
PIEBALDconsult21-Nov-12 17:51
mvePIEBALDconsult21-Nov-12 17:51 
GeneralRe: Manual Coding vs Code Generation Pin
Mycroft Holmes21-Nov-12 18:46
professionalMycroft Holmes21-Nov-12 18:46 
GeneralRe: Manual Coding vs Code Generation Pin
PIEBALDconsult22-Nov-12 9:51
mvePIEBALDconsult22-Nov-12 9:51 
AnswerRe: Manual Coding vs Code Generation Pin
PIEBALDconsult21-Nov-12 4:00
mvePIEBALDconsult21-Nov-12 4:00 
QuestionDesign Question Pin
PozzaVecia15-Nov-12 17:31
PozzaVecia15-Nov-12 17:31 
AnswerRe: Design Question Pin
DaveyM6915-Nov-12 19:31
professionalDaveyM6915-Nov-12 19:31 
GeneralRe: Design Question Pin
PozzaVecia15-Nov-12 20:11
PozzaVecia15-Nov-12 20:11 
AnswerRe: Design Question Pin
Rahul Rajat Singh15-Nov-12 21:43
professionalRahul Rajat Singh15-Nov-12 21:43 
GeneralRe: Design Question Pin
PozzaVecia15-Nov-12 23:14
PozzaVecia15-Nov-12 23:14 
AnswerRe: Design Question Pin
Rahul Rajat Singh15-Nov-12 23:22
professionalRahul Rajat Singh15-Nov-12 23:22 
AnswerRe: Design Question PinPopular
BobJanova15-Nov-12 23:12
BobJanova15-Nov-12 23:12 
GeneralRe: Design Question Pin
PozzaVecia15-Nov-12 23:16
PozzaVecia15-Nov-12 23:16 
GeneralRe: Design Question Pin
Rahul Rajat Singh15-Nov-12 23:35
professionalRahul Rajat Singh15-Nov-12 23:35 
GeneralRe: Design Question Pin
BobJanova16-Nov-12 0:09
BobJanova16-Nov-12 0:09 
AnswerRe: Design Question Pin
SledgeHammer0116-Nov-12 9:53
SledgeHammer0116-Nov-12 9:53 
GeneralRe: Design Question Pin
PozzaVecia16-Nov-12 10:06
PozzaVecia16-Nov-12 10:06 
AnswerRe: Design Question Pin
Clifford Nelson16-Nov-12 9:53
Clifford Nelson16-Nov-12 9:53 
QuestionBackground worker thread Pin
MAW3015-Nov-12 14:54
MAW3015-Nov-12 14:54 
AnswerRe: Background worker thread Pin
DaveyM6915-Nov-12 18:51
professionalDaveyM6915-Nov-12 18:51 
QuestionArray, Struct, Class??? I'm so confused.... Pin
KKW_acd15-Nov-12 6:29
KKW_acd15-Nov-12 6:29 
AnswerRe: Array, Struct, Class??? I'm so confused.... Pin
DaveyM6915-Nov-12 6:55
professionalDaveyM6915-Nov-12 6:55 
KKW_acd wrote:
righthand side of the line

You are correct. As the message says, you cannot initialize a field when it is first declared in a struct, all fields assume the default value for the type which in the case of an array is null. Initialization must be done in a constructor (however you cannot have a parameterless constructor for a struct either).

When to use a struct or a class can be complicated sometimes. I think your dtlst (horrible name by the way - why not DataList?) should most likely be a class. You will then be able to initialize the field as you wish.

Also, public fields are normally bad practice, make them private and use a property (getter only unless a setter is needed) to expose the field.

Edit: There's still a few things about this that don't feel right, but to fit your code and usage, this is a quick example of something that works. This is not meant to be doing your homework for you, but rather to point you in the correct direction and give you something to compare your code too:
C#
public struct Item
{
    private string name;
    private int index;

    public Item(string name, int index)
    {
        this.name = name;
        this.index = index;
    }

    // only getters as a struct should not normally be changed once created.
    public string Name { get { return name; } }
    public int Index { get { return index; } }
}

C#
public class DataList
{
    private Item[] items = new Item[128];

    public Item[] Items { get { return items; } }
}

C#
// usage
DataList[] dataLists = new DataList[128];

int listIndex = 0;
int itemIndex = 0;

string itemText = "Random text";
string indexText = "1";

dataLists[listIndex] = new DataList();

dataLists[listIndex].Items[itemIndex] = new Item(itemText, int.Parse(indexText));

Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)




modified 15-Nov-12 13:19pm.

GeneralRe: Array, Struct, Class??? I'm so confused.... Pin
KKW_acd15-Nov-12 9:03
KKW_acd15-Nov-12 9:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.