how to return two value in get() set() method?

Posted by Kalaikathiravan under C# on 11/8/2012 | Points: 10 | Views : 850 | Status : [Member] | Replies : 2
Hi friends... I have 1 doubt how to return the two value in get() set() in c#?




Responses

Posted by: Rajesh081725 on: 11/8/2012 [Member] Bronze | Points: 25

Up
0
Down
While reading about C# I came upon these Properties that seem to me like they are a simple way of hiding the get/set methods to access and modify variables inside a class and I wanted to know if they had any real advantages over the classical method. so would it be better to do this
using System;

class Person
{
private string myName ="N/A";
private int myAge = 0;

// Declare a Name property of type string:
public string Name
{
get
{
return myName;
}
set
{
myName = value;
}
}

// Declare an Age property of type int:
public int Age
{
get
{
return myAge;
}
set
{
myAge = value;
}
}

public override string ToString()
{
return "Name = " + Name + ", Age = " + Age;
}

public static void Main()
{
Console.WriteLine("Simple Properties");

// Create a new Person object:
Person person = new Person();

// Print out the name and the age associated with the person:
Console.WriteLine("Person details - {0}", person);

// Set some values on the person object:
person.Name = "Joe";
person.Age = 99;
Console.WriteLine("Person details - {0}", person);

// Increment the Age property:
person.Age += 1;
Console.WriteLine("Person details - {0}", person);
}
}


OR This
private string foreName;

public void getForeName()
{
return foreName;
}

public void setForeName(String name)
{
foreName = name;//with more code if needed
}



Time is Gold
Thanks & Regards,
Rajesh Kumar,
9962038582.

Kalaikathiravan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kalaikathiravan on: 11/8/2012 [Member] Starter | Points: 25

Up
0
Down
ok Thanks...

Kalaikathiravan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response