make a class property an array of an instantiated class?
-
v9ExportPacket p = new v9ExportPacket(); p.TemplateRecord = new TemplateRecord[5]; TemplateRecord t_tmp = new TemplateRecord(); t_tmp.FlowSetID=0; t_tmp.Length=10; t_tmp.id=23; t_tmp.FieldCount=4; t_tmp.Fields= new FieldPairs[t_tmp.FieldCount]; t_tmp.Fields[0] = new FieldPairs(1,2); t_tmp.Fields[1] = new FieldPairs(3,4); t_tmp.Fields[2] = new FieldPairs(5,6); t_tmp.Fields[3] = new FieldPairs(7,8); p.TemplateRecord[0] = t_tmp; i was wondering if there is a way that i could just use p.TemplateRecord[0].id=1; instead of having to create a TemplateRecord object t_tmp to set the properties of that class and then set the TemplateRecord[0] property object equal to t_tmp object. i have looked into using indexers but i haven't seen an example where you could access a property of an indexed property.
-
v9ExportPacket p = new v9ExportPacket(); p.TemplateRecord = new TemplateRecord[5]; TemplateRecord t_tmp = new TemplateRecord(); t_tmp.FlowSetID=0; t_tmp.Length=10; t_tmp.id=23; t_tmp.FieldCount=4; t_tmp.Fields= new FieldPairs[t_tmp.FieldCount]; t_tmp.Fields[0] = new FieldPairs(1,2); t_tmp.Fields[1] = new FieldPairs(3,4); t_tmp.Fields[2] = new FieldPairs(5,6); t_tmp.Fields[3] = new FieldPairs(7,8); p.TemplateRecord[0] = t_tmp; i was wondering if there is a way that i could just use p.TemplateRecord[0].id=1; instead of having to create a TemplateRecord object t_tmp to set the properties of that class and then set the TemplateRecord[0] property object equal to t_tmp object. i have looked into using indexers but i haven't seen an example where you could access a property of an indexed property.
If you create an indexer and the object is a class, it's passed by reference, so you can automatically alter indexed properties.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
v9ExportPacket p = new v9ExportPacket(); p.TemplateRecord = new TemplateRecord[5]; TemplateRecord t_tmp = new TemplateRecord(); t_tmp.FlowSetID=0; t_tmp.Length=10; t_tmp.id=23; t_tmp.FieldCount=4; t_tmp.Fields= new FieldPairs[t_tmp.FieldCount]; t_tmp.Fields[0] = new FieldPairs(1,2); t_tmp.Fields[1] = new FieldPairs(3,4); t_tmp.Fields[2] = new FieldPairs(5,6); t_tmp.Fields[3] = new FieldPairs(7,8); p.TemplateRecord[0] = t_tmp; i was wondering if there is a way that i could just use p.TemplateRecord[0].id=1; instead of having to create a TemplateRecord object t_tmp to set the properties of that class and then set the TemplateRecord[0] property object equal to t_tmp object. i have looked into using indexers but i haven't seen an example where you could access a property of an indexed property.
Not really clear on what you're trying to do, but I'll take a stab at it. The important thing to remember when trying to access an index is what is it returning me? For instance, take a DataSet.
DataSet ds; DataTable dt = ds.Tables[0]; // Gives you a DataTable (the first one in the dataset). DataRow dr = ds.Tables[0].Rows[0]; // Gives you a DataRow (the first row, of the first table, in the data set). object o = ds.Tables[0].Rows[0][0]; // Gives you an object (the value of the first column, in the first row, of the first table in the dataset).
So, you can continue to index off a property, as long as that property contains an index operation. For your case, you might need to create a 'Collection' class that simply holds a collection of items for you. Assuming I'm even close on what you're asking a question about. :cool: Hope that helps.
-
Not really clear on what you're trying to do, but I'll take a stab at it. The important thing to remember when trying to access an index is what is it returning me? For instance, take a DataSet.
DataSet ds; DataTable dt = ds.Tables[0]; // Gives you a DataTable (the first one in the dataset). DataRow dr = ds.Tables[0].Rows[0]; // Gives you a DataRow (the first row, of the first table, in the data set). object o = ds.Tables[0].Rows[0][0]; // Gives you an object (the value of the first column, in the first row, of the first table in the dataset).
So, you can continue to index off a property, as long as that property contains an index operation. For your case, you might need to create a 'Collection' class that simply holds a collection of items for you. Assuming I'm even close on what you're asking a question about. :cool: Hope that helps.
-
If you create an indexer and the object is a class, it's passed by reference, so you can automatically alter indexed properties.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Okay so let me see if i understand you correctly. I have two classes. Class A and Class B. I give class A 5 properties int prop1(){} int prop2(){} int prop3(){} int prop4(){} classB prop5(){} what i would like to do is to create a 5th property and make its type equal to ClassB. but i would also like to index this property too. BTW Class B also has some properties to it. So in the end i would be able to access my items like this: classA xyz = new classA(); xyz.prop1=1; xyz.prop2=2; xyz.prop3=3; xyz.prop4=4; xyz.prop5[0].prop1=1; xyz.prop5[0].prop2=2; xyz.prop5[1].prop1=1; xyz.prop5[1].prop2=2; I remember doing stuff like this a while ago in VB6 but i'm pretty new to C# and i'm just learning out to do this sort of stuff. I hope that explain helps a little bit more. I think i understand what your saying though.