Parse class variables?

I'm pretty new to c# language as I just started to use it several weeks ago, and I came across one simple problem with classes.I was sitting for good 30 minutes looking for answers and just couldn't figure out how to fix it. This is my code so far:

class Program
{
    static void Main(string[] args)
    {
        Plyta p1;
        Plyta p2;
        p1 = new Plyta(p1.ImtiIlgi(), p1.ImtiAuksti());


        p1.ImtiIlgi();
        Console.Write("\niveskite plytos ilgi - ");
        p1.PlytosIlgis = int.Parse(Console.ReadLine());

        p1.ImtiAuksti();
        Console.Write("\niveskite plytos auksti - ");
        p1.PlytosAukstis = int.Parse(Console.ReadLine());

and the class file:

class Plyta
{
    private int ilgis,
                aukstis;

    public Plyta(int PlytosIlgis, int PlytosAukstis)
    {
        ilgis = PlytosIlgis;
        aukstis = PlytosAukstis;
    }


    public int ImtiIlgi() 
    {
        return ilgis;
    }

    public int ImtiAuksti()
    {
        return aukstis;
    }
}

and when I run it, it gives the following error:

'praktika.Plyta' does not contain a definition for 'PlytosIlgis' and no extension method 'PlytosIlgis' accepting a first argument of type 'praktika.Plyta' could be found (are you missing a using directive or an assembly reference?)

I assume I'm writing the wrong variable to parse but whatever I thought of doesn't work, any help for a begginner? :)

Jon Skeet
people
quotationmark

I think you're confused about what your methods are doing, and when you're initializing objects. I suspect you actually want to do something like this:

class Program
{
    static void Main(string[] args)
    {
        // Ask the user for the relevant data
        Console.WriteLine("iveskite plytos ilgi - ");
        int ilgis = int.Parse(Console.ReadLine());

        Console.WriteLine("iveskite plytos auksti - ");
        int aukstis = int.Parse(Console.ReadLine());

        // Now we're in a position to create the object
        Plyta p1 = new Plyta(ilgis, aukstis);

        // And we can read the value back from the property
        Console.WriteLine(p1.Ilgis);
    }
}

class Plyta
{
    // These are public, read-only automatically-implemented properties
    public int Ilgis { get; }
    public int Aukstis { get; }

    public Plyta(int ilgis, int aukstis)
    {
        // Set the properties...
        Ilgis = PlytosIlgis;
        Aukstis = PlytosAukstis;
    }
}

(This uses C# 6's read-only automatically-implemented properties. Let me know if you're not using C# 5.)

people

See more on this question at Stackoverflow