Can i return a class from a method?
-
Hi Friends I have two Classes Class A and Class B. In class A i have one method xyz which collects data from database and fills properties of class B. Can I return class B from method xyz ? if then can i access properties of class B at its calling point. thanks
Naveed Kamboh
-
Hi Friends I have two Classes Class A and Class B. In class A i have one method xyz which collects data from database and fills properties of class B. Can I return class B from method xyz ? if then can i access properties of class B at its calling point. thanks
Naveed Kamboh
I hope you are saying of returning an object from another class???
-
Hi Friends I have two Classes Class A and Class B. In class A i have one method xyz which collects data from database and fills properties of class B. Can I return class B from method xyz ? if then can i access properties of class B at its calling point. thanks
Naveed Kamboh
using System; using System.Web; public partial class Trial : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Test test1 = this.ReturnClass("Hello"); Response.Write("" + test1.name); } protected Test ReturnClass(string var) { Test test = new Test(); test.name = var; return test; } public class Test { public string name; protected string Place; } } Is this the thing u want?
Koushik
-
using System; using System.Web; public partial class Trial : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Test test1 = this.ReturnClass("Hello"); Response.Write("" + test1.name); } protected Test ReturnClass(string var) { Test test = new Test(); test.name = var; return test; } public class Test { public string name; protected string Place; } } Is this the thing u want?
Koushik
Yes it is, let me try . thanks
Naveed Kamboh
-
using System; using System.Web; public partial class Trial : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Test test1 = this.ReturnClass("Hello"); Response.Write("" + test1.name); } protected Test ReturnClass(string var) { Test test = new Test(); test.name = var; return test; } public class Test { public string name; protected string Place; } } Is this the thing u want?
Koushik
interface IMyClass{
...
}public class ClassA : IMyClass{
...
}public class ClassB : IMyClass{
...
}public partial class Trial : System.Web.UI.Page{
protected IMyClass ReturnClass(string var){
if("Something".Equals(var))
return new ClassA();
else
return new ClassB();
}
}
File Not Found