Click here to Skip to main content
15,943,406 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In one is able to return an entire class and access the variables in the class from another class. I am having the most difficult time understanding how to accomplish this in C#.

in I can do somehting like this...

Function getFinal(ByVal dblONE, ByVal intTWO)

Dim report1 as New Class2_REPORT

report1.Summed_TOTAL = dblONE + intTWO

report1.Subtracted_TOTAL = dblONE - intTWO

Return report1

End Function

I am unable to do the same thing in C# since the function is expecting that I return something since I am calling this method from another class. But I cant return more than one value in C# so my understanding is that I need to return an "entire class". Any help is appreciated. I have been searching for a solution to this for a while and cannot find anything.

Actually you can return (a reference to) an entire object in C#, try:
class MyPoint
    public int x, y;
 class Program
     static public MyPoint getOrigin()
         MyPoint p = new MyPoint();
         p.x = p.y = 0;
         return p;
     static void Main(string[] args)
         MyPoint O=getOrigin();
         Console.WriteLine("O=({0},{1})", O.x, O.y);
Share this answer
U can do the same thing in C#. Remember that in C# instances of a class are references.

class A{
    public static int a;
    public static double b;

    public A(){
    //constructor implementation

A myFunction(int parameter1, double parameter2){
    A result = new A();
    A.a = parameter1;
    A.b = parameter2;
    return A;

This function should return a reference to an instance of class A.

Hope this answers your question.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900