如何在一个对象中传递数据 [英] how to pass data in one object

查看:42
本文介绍了如何在一个对象中传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个对象,我可以在一个结果集中设置该对象,并且所有数据都将设置...我在这里做错了所有类型的数组,而不是我必须使一个数组对象有任何帮助吗?



I want to make an object from which i can set that object in one result set and the all data will set ...i made here mistake to make arrays of all types rather i had to make one array object any helps ?

String DOC_no = "9EMP11ROUTE112102012_132143";
String date = "23/11/2012";
String salesman = "EMP11-Ankit";
String route = "ROUTE1-Vaniya area";
String total_cash = "350";
String total_cheque_amt = "000";
String total_cc_amt = "200";
String total_collection = "550";

String[] pay_type = new String[] { "Cash", "Credit" };
String[] amt = new String[] { "100", "200" };
String[] chDate = new String[] { " ", " " };
String[] bName = new String[] { "ICICI", " " };
String[] ccNo = new String[] { "123", " " };
String[] refno = new String[] { "5677", " " };

// method to make file in sd card
fileGenOnSD.generateOnSDForReceiptReport("ReceiptReport.txt",
        DOC_no, date, salesman, route, pay_type, amt, chDate,
        bName, ccNo, refno, total_cash, total_cc_amt,
        total_cheque_amt, total_collection);





这是我的代码我只需要将所有数组放在一个结果集中,我需要传递方法,它的紧急任何帮助吗?



this is my code i just need to put all arrays in one result set which i need to pass in method , its urgent any help please ??

推荐答案

你可以创建该对象的Dictionary并将Dictionary对象发送给您方法,在方法内部,您可以访问Dictionary对象中的值

,如下面的代码所示



You can create the Dictionary of that object and send the Dictionary object to you method and inside the method you can access the values from the Dictionary object
as below mentioned in the code

Dictionary<string,string> lstString = new Dictionary<string, string>();
            lstString.Add( "DOC_no", "9EMP11ROUTE112102012_132143" );
            lstString.Add( "date", "23/11/2012" );
            //.... other values
            //....
            //....

            Dictionary<string,string[]> lstStringArray = new Dictionary<string, string []>();
            lstStringArray.Add( "pay_type ", new String [] { "Cash", "Credit" } );
            lstStringArray.Add( "amt", new String [] { "100", "200" } );
            //.... other values
            //....
            //....

            //Now to get the value from dictionary in side your method pass the parameter and get the value

            string DOC_no = null;
            lstString.TryGetValue( "DOC_no", out DOC_no );


            string[] pay_type = null;
            lstStringArray.TryGetValue( "pay_type", out pay_type );


这篇关于如何在一个对象中传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆