This is the way i am going but couldnt get the solution ..
Hey ,
I got to print out a square on a console. In which class Square should contain two constructors and an instance property, Side that has a get and set accessors for private data. The first constructor that takes no arguments and another takes a side length as a value.
Then define a test application to test the Square functions which are been defined.
The way i am going through this problem is :
using System;
namespace ConsoleApplication2
{
public class Square
{
public int m_Side; // m_Side is a member variable with the value of side
public Square() // Default Constructor
{
m_Side = 0;
}
public Square(int SideValue) // Constructor which takes side as argument
{
m_Side = SideValue;
}
public int Side
{
get
{
return m_Side;
}
set
{
if(value>0)
m_Side = value;
else
m_Side = 0;
}
}
}
}
The test appliation i define is :
using System;
namespace ConsoleApplication2
{
/// <summary>
/// Summary description for SquareTest.
/// </summary>
public class SquareTest
{
static void Main ()
{
Console.WriteLine( "Enter Side Value ");
Square S1= new Square();
S1.m_Side=Int32.Parse( Console.ReadLine());
if ( S1.m_Side>0)
{
for ( int S1=0; S1<m_Side; S1++)
{
for ( int S1=0; S<m_Side; S1++)
{
System.Console.WriteLine +="*";
}
System.Console.WriteLine +="\n";
}
}
}
}
}
The test application doesnt works as there are loads of errors..
Please update me with a solution as i am new to C# and couldn't figure it out as how to get through with this problem.
Cheers!!
|