interface

N

nicol

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;
}
}
}
 
V

vanderghast

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top