我如何可以提取在C#中从一个类的对象字段 [英] How can i extract fields from a class object in c#

查看:185
本文介绍了我如何可以提取在C#中从一个类的对象字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有有一些属性的类

public class SendData
{
public int MerchantID{get; set;}
public string Name{get; set;}
public int Age{get; set;}
}

和按钮的点击和用户数据初始化这个类的对象。

And on button click and initializing user data to the object of this class.

button_click()
{
SendData senddata = new SendData();

senddata.MerchantID = Convert.ToInt32(txtMerchantid.Text);
senddata.Age = Convert.ToInt32(txtAge.Text);
senddata.Name= txtName.Text;

Webservice1.ReceiveDataService serviceObj = new Webservice1.ReceiveDataService();

public bool result = serviceObj.UpdateData(senddata); // calling web service
if(result) //Here is the scenario
lblresult.Text="Updated";
else
lblresult.Text="Operation unsuccessful";
}

现在我怎么可以从web服务方法,这个对象读取所有领域?

Now how can i read all the fields from this object on the webservice method?

我的WebMethod:

My webmethod:

public bool updatedata()//How to pass that object here
{
 //How can i get those three values in three separate fields in this method like.
 string name =""; //that name from UI;
 int id = ;//Id from UI
 int age= ;//Age from UI 
 //All the field need to be stored in database those coding will come here.
 return true;
}

它很简单,但请大家帮我,也ü可以建议我实现一些最好的替代方法。
谢谢,

Its quite simple but please help me and also u can suggest me some best and alternate way to achieve. Thanks,

推荐答案

您需要有类型的参数的SendData ,这种类型的应该是网络present服务应用程序和访问到消费应用程序。

You need to have a parameter of type SendData, This type should be present in web service application and accessible to the consuming application.

public bool updatedata(SendData sendDate)//How to pass that object here
{
    //How can i get those three values in three separate fields in this method like.
    string name =""; //that name from UI;
    int id = ;//Id from UI
    int age= ;//Age from UI 
}

这篇关于我如何可以提取在C#中从一个类的对象字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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