How to fix this please? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to fix this please?

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sololearn { class Program { class Shape { private int dimensions; public Shape(int dimensions) { this.dimensions = dimensions; int[] parts = new int[dimensions+1]; } public int[] parts; public static Shape operator * (Shape P1, Shape P2) { Shape P = new Shape(P1.dimensions+P2.dimensions); for (int x=0; x<=P.dimensions; x++) { for (int y=0; y<=P1.dimensions; y++) { for (int z=0; z<=P2.dimensions; z++) { if (x==y+z) P.parts[x]+=P1.parts[y]*P2.parts[z]; }} } return P; } }

23rd Sep 2022, 5:22 PM
TheMasterBee
TheMasterBee - avatar
3 Answers
+ 1
Save code in playground and share link here.. Don't redeclare parts in constructor. parts = new int[ dimension+1]; // don't include type int[] again... Use < instead <=.
23rd Sep 2022, 6:14 PM
Jayakrishna 🇮🇳
0
static void Main(string[] args) { Shape seg = new Shape(1); seg.parts = new int[] {2,1}; Shape squ = new Shape(2); squ.parts = new int[] {4,4,1}; Shape prod = seg * squ; } } }
23rd Sep 2022, 5:23 PM
TheMasterBee
TheMasterBee - avatar
0
Copy and see it.!
23rd Sep 2022, 5:23 PM
TheMasterBee
TheMasterBee - avatar