-2
我試圖給C#中的列表賦值。我有以下類:分配給C#中的列表
public class Request
{
public string firstName { get; set; }
public string lastName { get; set; }
public string email { get; set; }
public List<Service> services { get; set; }
}
public class Service
{
public string sku { get; set; }
public string did { get; set;}
}
我用下面的代碼在我的控制器:
public async Task<IHttpActionResult> GetCases()
{
var client = await
SalesforceService.GetUserNamePasswordForceClientAsync();
//Select All Cases Where Status = New.
var cases = await client.QueryAsync<Case>("SELECT Id,
Description FROM Case Where Status='New'");
var sfCases = cases.Records.Select(c => new
{
c.Description
});
List<Request> requestresults = new List<Request>();
foreach (var c in sfCases)
{
var sfrequest = new Request();
if (c.Description != null)
{
string[] descriptionline = null;
sfrequest.Description = c.Description;
descriptionline = Regex.Split(c.Description, "\r\n");
if (descriptionline.Any(x => x.Contains("FirstName")))
{
var firstnameindex = Array.FindIndex(descriptionline, row => row.Contains("FirstName"));
sfrequest.firstName = descriptionline[firstnameindex].Replace("FirstName - ", "");
var lastnameindex = Array.FindIndex(descriptionline, row => row.Contains("LastName"));
sfrequest.lastName = descriptionline[lastnameindex].Replace("LastName - ", "");
var emailindex = Array.FindIndex(descriptionline, row => row.Contains("Email"));
sfrequest.email = descriptionline[emailindex].Replace("Email - ", "");
var skuindex = Array.FindIndex(descriptionline, row => row.Contains("sku"));
如何搶sku
和did
併爲它們分配的方式,我做了其他性質相同?
什麼和你的問題到底在哪裏?在代碼中突出顯示它.. – Coding
歡迎來到Stack Overflow!當提出問題時,請嘗試製作[最小完整且可驗證](https://stackoverflow.com/help/mcve)您問題的示例。現在你有很多代碼可能與這個問題沒有多大關係。正如@Coding所述,目前還不清楚問題的癥結所在。這並不容易,但它是使用軟件的一部分。 –