From: nicol on
using System;

class Program
{
static void Main(string[] args)
{
your_number a = new your_number();
a.sides = Int32.Parse(Console.ReadLine());
}
}
public interface number
{
//public int side;
int sides
{
set;
get;
}
}
public class your_number : number
{
public int sides
{
set
{
sides = value;
Console.WriteLine(sides);
}
get
{
return sides;
}
}
}



From: vanderghast on
Sounds fishy, but it is about the properties, not about the interface, you
probably miss the variable which has to hold the data. The property itself
is just a kind of label to exchange information, not a container. Try the
following three modifications:



public class your_number : number
{
int m_sides; // <------------
public int sides
{
set
{
m_sides = value; // <-------------
Console.WriteLine(sides);
}
get
{
return m_sides; // <--------------
}
}
}



I have not tested if you code compile, but with

public int sides
set
{
sides = value
}


that sounds a little bit recursive (if it compiles). You are telling the
computer what to do when your code use

sides = something

but your code does exactly the same, so it call your code, calling your
code, over and over, not even reaching the line where you impose to write
something in the console window. With the proposed modification, the value
send is stored locally, rather than trying to call the set definition of the
property sides again.



Vanderghast, Access MVP


"nicol" <nicol.young20(a)gmail.com> wrote in message
news:3f07fb75-6592-4353-b18a-baf9602fb893(a)v29g2000prb.googlegroups.com...
> using System;
>
> class Program
> {
> static void Main(string[] args)
> {
> your_number a = new your_number();
> a.sides = Int32.Parse(Console.ReadLine());
> }
> }
> public interface number
> {
> //public int side;
> int sides
> {
> set;
> get;
> }
> }
> public class your_number : number
> {
> public int sides
> {
> set
> {
> sides = value;
> Console.WriteLine(sides);
> }
> get
> {
> return sides;
> }
> }
> }
>
>
>