Ошибки: Конструктор не может вызвать сам себя. Неоднозначный вызов следующих методов или свойств - C#
Формулировка задачи:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace exe1
{
//****************EXE1***********
enum Material
{
StainlessSteel = 1,
Aluminum,
ReinforcedConcrete,
Composite,
Titanium
}
enum CrossSection
{
Ibeam = 1,
Box,
Zshaped,
Cshaped
}
enum TestResult
{
Pass = 1,
Faile
}
//***************Exe 3******************
class StressTestCase
{
public Material girderMaterial;
public CrossSection crossSection;
public int lengthInMm, heightInMm, widthInMm;
public StressTestCase( ){ }
public StressTestCase(Material girder, CrossSection cross, int length, int heigth, int widht)
: this(Material.Aluminum, CrossSection.Box, length, heigth, widht)
public StressTestCase(Material girder, CrossSection cross, int length, int heigth, int widht)
{
girderMaterial = girder;
crossSection = cross;
lengthInMm = length;
heightInMm = heigth;
widthInMm = widht;
}
public void ShowInfo()
{
Console.WriteLine("{0} {1} {2} {3} {4}",girderMaterial,crossSection,lengthInMm,heightInMm,widthInMm /*stressTestCase*/ );
}
}
class Program
{
static void Main()
{
}
}
}строчка 41 (StressTestCase) Конструктор не может визвать сам себя Строчка 42 (: this(Material.Aluminum, CrossSection.Box, length, heigth, widht)) неоднозначный вызов следующих методов или свойств
Решение задачи: «Ошибки: Конструктор не может вызвать сам себя. Неоднозначный вызов следующих методов или свойств»
textual
Листинг программы
class A
{
public int x, y;
public A(int x) {
this.x = x;
}
// тут сначала будет вызов подходящего конструктора, т.е A(int x) ибо x в данном случае int.
public A(int x, int y) : this(x)
{
this.y = y;
}
}