如何将值添加到变量 [英] How to add the value to the variable

查看:164
本文介绍了如何将值添加到变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我必须发送电子邮件,并且我有电子邮件代码.其中有一些参数(例如电子邮件地址,a,b等).因此,在发送电子邮件时,它将从参数中获取信息.我的疑问是

Hi,

I have to send a email and i have email code. In that there are parameters (like email address, a, b and etc). So while sending the email, it is taking the info from parameters. My doubt is

public static void SendEmail(string FirstName, string LastName, string emailAddress, string BODY, string TASKID)



在上面提到的行中,我使用了字符串emailAddress作为参数之一,并且我编写了代码以获取其他页面中的电子邮件地址,如下所示:




In the above mentioned line, i have used string emailAddress as one of the parameter and i have written the code to get the email address in other page as shown below:


List<String> updateAddresses = new List<String>();
            foreach (var person in personResults.Results)
            {
                string addr = null;

                addr = person.Artifact.Fields.Single(
                        field => field.Guids.Contains(GUIDCollection.EMAIL_ADDRESS_GUID)
                    ).ValueAsFixedLengthText;

                if ((addr != null) && (addr != ""))
                {
                    updateAddresses.Add(addr);
                }
            }



因此,现在,如果做emailAddress = UpdatedAddress.Add(addr),它给出了错误.现在如何将值转换为emailAddress字符串?任何帮助将不胜感激.

我尝试过的事情:

尝试将字符串addr重命名为emailAddress.不确定它是否正确.



So now, if do emailAddress = updatedAddress.Add(addr), it is giving error. Now how to get the value into emailAddress string? Any help would be appreciated.

What I have tried:

Tried renaming the string addr to emailAddress. Not sure whether it is correct or not.

推荐答案

在声明一个方法(如SendEmail方法)时,将提供由数据类型组成的参数,以及用于存储数据的变量的名称.
就像您拥有以下内联代码一样:
When you declare a method, like your SendEmail method, you provide parameters which consist of the type of the data, and the name of a variable to store the data in.
It''s just like you had this inline code:
string myName = "OriginalGriff";
string yourName = "Member 8010354";
...
string userName = myName;
username = "The user's name is: " + userName;
Console.WriteLine(userName);
...
username = yourname;
username = "The user's name is: " + userName;
Console.Writeline(username);
...

您可以使用通用代码"并使其成为一种方法:

You could take the "common code" and make that a method:

public void ShowUsername(string userName)
   {
   username = "The user's name is: " + userName;
   Console.Writeline(username);
   }
...
string myName = "OriginalGriff";
string yourName = "Member 8010354";
ShowUsername(myName);
ShowUsername(yourName);

参数变量的名称仅在方法内部相关,无法在外部访问.

就您而言,您要做的就是调用SendEmail并将相关的参数数据传递给它:

The name of the parameter variable is only relevant inside the method, it can''t be accessed outside.

In your case, all you have to do is call SendEmail and pass it the relevant parameter data:

SendEmail("Original", "Griff", originalGriffEmailAddress, "Hello!", "I have no idea what a task id is");

只要变量originalGriffEmailAddress存在并且将我的电子邮件地址保存为字符串,它就会起作用.

比我更具体的说:您不显示调用方法的位置,也不显示所显示的foreach循环代码适合您的程序的位置.

As long as the variable originalGriffEmailAddress exists and holds my email address as a string, it''ll work.

More specific than that I can''t be: you don''t show where you call the method, or where that foreach loop code you show fits into your program.


这篇关于如何将值添加到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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