Link to home
Start Free TrialLog in
Avatar of goodk
goodkFlag for United States of America

asked on

classes passing variables

The following is only an example.  I need to pass several variables when Call myTable.

Is passing variables like this is a better thing or what is a more professional way? thanks


 public static string myTable( string xTable)
        {

               string txTable = MiscStrings.fRQueryString("xqTable");  // returns blank or the variable

if (txTable.Length <1) txTable=xTable

// Use the variable

}
Avatar of binaryevo
binaryevo
Flag of United States of America image

Its perfectly fine to do it this way or you could also pass in an object as an alternative.  See below:

Object Definition
public class Table
{
       public string TableName{get;set;}
       public string Description{get;set;}
}

Open in new window


Modified Method

public static string myTable(Table xTable){

     //here you can unpack the contents of the object
     string name = xTable.Name;
     string description = xTable.Description;
}

Open in new window


Hope this helps
Avatar of goodk

ASKER

Can you give a little more detail?

Like how do we use it and how do we set the value? thanks
Avatar of goodk

ASKER

Is this how it works?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace myCLib
{
    public class gVariables
    {
        /* How to use
        gVariables gVar = new gVariables();

        gVar.SetID(1);
        gVar.SetName("Amelio Rosales");

        */
        private int m_id = -1;

        public int GetID()
        {
            return m_id;
        }

        public void SetID(int id)
        {
            m_id = id;
        }

        private string m_name = string.Empty;

        public string GetName()
        {
            return m_name;
        }

        public void SetName(string name)
        {
            m_name = name;
        }

    }
}
If your referring to setting the value of the object that your going to pass into the myTable method then you can do it like so:

Table table = new Table();
table.Name = "My Test Name";
table.Description = "My Test Description";
string myTableResult = myTable(table);

Open in new window

Avatar of goodk

ASKER

so could I continue to define table
table.Name2= "My Test Name2" ??
Avatar of goodk

ASKER

able table = new Table();
table.Name = "My Test Name";
table.Description = "My Test Description";
table.Description2 = "My Test Description2";
table.Description3 = "My Test Description3";
string myTableResult = myTable(table);


Is above correct?
ASKER CERTIFIED SOLUTION
Avatar of goodk
goodk
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of goodk

ASKER

solution is not understood