cześć,
muszę stworzyć prywatny konstruktor parametryczny, który jest używany do czegoś, np. przez jakiś
inny konstruktor a nie mam pojęcia jak to zrobić. Nie wiem jak odwołać się do niego skoro jest prywatny. Ma ktoś jakiś pomysł?
z góry dziękuje za pomoc
0
5
public class T
{
public string Something { get; set; }
private T(string input)
{
this.Something = input;
}
public static T CreateInstanceOfT(string input)
{
return new T(input);
}
}
2
Można zrobić coś takiego:
using System;
class Klasa
{
private Klasa(int i)
{
Console.WriteLine($"Konstruktor prywatny, i = {i}");
}
public Klasa()
: this(123)
{
Console.WriteLine("Konstruktor publiczny");
}
}
class Program
{
static void Main(string[] args)
{
new Klasa();
}
}
0
Dziekuje bardzi