Good Morning, Dabbu.
I've tested your code and the line you said that you had a problem actually
worked. I couldn't understand exactly what you need, but, since you want to
break the program if the value of count is less than 0, you could retrieve
the count information from a property and with that, you could prevent from
access an index which doesn't exist.
Something like this:
public class Employee<T>
{
public int RealCount
{
get { return count; }
}
private T[] data = new T[10];
private static int count = 0;
public T Value
{
get
{
return this.data[--count];//This Line Have A Problem
}
set
{
this.data[count] = value;
count++;
}
}
for (int i = 0; i < 10; i++)
{
if (name.RealCount > 0)
{
Console.WriteLine("The Name OF Employee---> " +
name.Value);
}
}
If you want to break, than you've got to choose what generic List you want
to control.
On Wed, Oct 21, 2009 at 12:55 AM, Dabbu <[email protected]> wrote:
>
> Good Morning sir .....
>
> I would like to break the program as well as the value of count
> becomes less than 0......
> but not successful to accomplish this task.
>
> i have use function instead of property and exception habdling
> techniche but the result is same
>
> please help me
>
> using System;
> using System.Collections.Generic;
> using System.Linq;
> using System.Text;
>
> namespace Generic4
> {
> class Program
> {
> static void Main(string[] args)
> {
> Employee<string> name = new Employee<string>();
> Employee<int> age = new Employee<int>();
> Employee<double> salary = new Employee<double>();
> for (int i = 0; i < 10; i++)
> {
> Console.Write("Enter The Name Of The Employee---> ");
> name.Value = Console.ReadLine();
> Console.Write("Enter The Age Of The Employee----> ");
> age.Value = Int32.Parse(Console.ReadLine());
> Console.Write("Enter The Salary Of The Employee---->
> ");
> salary.Value = Double.Parse(Console.ReadLine());
> }
> Console.Clear();
> for (int i = 0; i < 10; i++)
> {
> Console.WriteLine("The Name OF Employee---> " +
> name.Value);
> Console.WriteLine("The Age Of The Employee---> " +
> age.Value);
> Console.WriteLine("The Salary Of The Employee---> " +
> salary.Value);
> Console.WriteLine();
> }
> }
> }
> public class Employee<T>
> {
> private T[] data = new T[10];
> private static int count = 0;
> public T Value
> {
> get
> {
> return this.data[--count];//This Line Have A Problem
> }
> set
> {
> this.data[count] = value;
> count++;
> }
> }
> }
> }
>
>
> Thanks Sir
>
--
Atenciosamente,
Paulo Roberto S. Pellucci