Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Can i return a class from a method?

Can i return a class from a method?

Scheduled Pinned Locked Moved ASP.NET
databasequestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Naveed Kamboh
    wrote on last edited by
    #1

    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 S 2 Replies Last reply
    0
    • N 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 Offline
      I Offline
      Irshad Sulaimani
      wrote on last edited by
      #2

      I hope you are saying of returning an object from another class???

      1 Reply Last reply
      0
      • N 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

        S Offline
        S Offline
        Spunky Coder
        wrote on last edited by
        #3

        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

        N E 2 Replies Last reply
        0
        • S Spunky Coder

          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

          N Offline
          N Offline
          Naveed Kamboh
          wrote on last edited by
          #4

          Yes it is, let me try . thanks

          Naveed Kamboh

          1 Reply Last reply
          0
          • S Spunky Coder

            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

            E Offline
            E Offline
            Ennis Ray Lynch Jr
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups