You can return a object of a class from a method. This is simple program which is returning the object of share class. You can see that the class variable value is also returning.
using System;
namespace ConsoleHub
{
class Share
{
public int ShareNumber = 299;
}
class Programs
{
static void Main(string[] args)
{
Share ObjS = ObjFactory();
Console.WriteLine("The Return Object is: ");
Console.WriteLine(ObjS.ToString());
Console.WriteLine(ObjS.ShareNumber);
Console.ReadLine();
}
static Share ObjFactory()
{
Share objShare = new Share();
objShare.ShareNumber = 201;
return objShare;
}
}
}
No comments:
Post a Comment