My problem is that i can't search into an array using linq in order to find an object property and set that as an id.
I need the method to search in the array for other model.idCliente and set that value as the "nextid + 1", in order to use it as id and the next array index.
Since the array's empty, the program adds the new object correctly, but when entering in the else if case, i get an axception for "a as null".
This is my code (where i get an exception on the else if linq line saying that "a" is null):
//Arrays
ClienteModel[] MemoryClienti = new ClienteModel[19];
OrdineModel[] MemoryOrdini = new OrdineModel[19];
//Aggiungi
public bool CreateCliente(ClienteModel model)
{
if (MemoryClienti[0] == null)
{
int defaultID = 0;
int defaultIndex = 0;
model.IDCliente = defaultID;
MemoryClienti[defaultIndex] = model;
}
else if (MemoryClienti[0]!=null)
{
var maxID = MemoryClienti.Max(a => a.IDCliente);
model.IDCliente = maxID++;
MemoryClienti[maxID++] = model;
}
return true;
}
This is the code of the form click:
//Aggiungi Cliente
private void aggiungiClienteButton_Click(object sender, EventArgs e)
{
clienteModel.Cognome = cognomeTextBox.Text;
clienteModel.Nome = nomeTextBox.Text;
clienteModel.Indirizzo = indirizzoTextbox.Text;
dbMemoryManager.CreateCliente(clienteModel);
MessageBox.Show("Cliente aggiunto correttamente.");
cognomeTextBox.Text = String.Empty;
nomeTextBox.Text = String.Empty;
indirizzoTextbox.Text = String.Empty;
}
This is the ClienteModel class:
public class ClienteModel
{
public int IDCliente { get; set; }
public string Cognome { get; set; }
public string Nome { get; set; }
public string Indirizzo { get; set; }
}
Wouldn't the following code achieve what you are trying to do?
ClienteModel[] MemoryClienti = new ClienteModel[19];
OrdineModel[] MemoryOrdini = new OrdineModel[19];
int maxID = 0; /* 0 is not a valid ID. IDs start from 1 */
//Aggiungi
public bool CreateCliente(ClienteModel model)
{
if(maxID <= MemoryClienti.Length) {
MemoryClienti[maxID++] = model; // copy the reference
model.IDCliente = maxID; // update the object's ID
return true;
} else {
return false; // can't add. array is full
}
}
If you are also doing deletions, you are better off using a List as others have also suggested.
Related
I've run into this interesting issue where I get an System.InvalidCastException: 'Specified cast is not valid.' while trying to cast my object inside my Dictionary<string, object> to and (int). Inside this Dictionary I store state for the current Game someone is playing and want to re-save / re-load the data if the game requires a save or has been closed. This method is only for reading the save not saving it.
Many Thanks in Advance.
Code:
public async Task ReadGameFileInAsync(string gameVersion)
{
var gameSave = new Dictionary<string, object>();
if (gameVersion == "bronze")
gameSave = JsonConvert.DeserializeObject<Dictionary<string, object>>(await ReadFileInAsync(BronzeGameSaveFilePath));
else if (gameVersion == "silver")
gameSave = JsonConvert.DeserializeObject<Dictionary<string, object>>(await ReadFileInAsync(SilverGameSaveFilePath));
_GameStats.CurrentGame = (int)gameSave["CurrentGame"]; //Error throws here.
_GameStats.CurrentWord = (int)gameSave["CurrentWord"];
_GameStats.Score = (int)gameSave["Score"];
_GameStats.BestScore = (int)gameSave["BestScore"];
_GameStats.Difficulty = (int)gameSave["Difficulty"];
_GameStats.IsNewGame = (bool)gameSave["IsNewGame"];
_GameStats.IsContinue = (bool)gameSave["IsContinue"];
_GameStats.IsUnlocked = (bool)gameSave["IsUnlocked"];
_GameStats.GameVersion = (string)gameSave["GameVersion"];
_GameStats.Cards = (ObservableCollection<LevelCardGroup>)gameSave["Cards"];
}
GameStats:
public class GameStats : IGameStats
{
public int CurrentGame { get; set; } = 1;
public int CurrentWord { get; set; } = 1;
public int Score { get; set; } = 0;
public int BestScore { get; set; } = 0;
public bool IsNewGame { get; set; } = true;
public bool IsContinue { get; set; } = false;
public bool IsUnlocked { get; set; } = false;
public bool ContinueButtonPressed { get; set; } = false;
public string GameVersion { get; set; } = string.Empty;
public int Difficulty { get; set; } = 3;
public ObservableCollection<LevelCardGroup> Cards { get; set; } = new ObservableCollection<LevelCardGroup>();
public void ResetGameStats(string gameVersion = "")
{
CurrentGame = 1;
CurrentWord = 1;
Score = 0;
BestScore = 0;
IsNewGame = true;
IsContinue = false;
GameVersion = gameVersion;
Difficulty = 3;
Cards.Clear();
}
}
Just deserialize to the class instance and copy data from it:
public async Task ReadGameFileInAsync(string gameVersion)
{
var gameSave = gameVersion switch
{
"bronze" => JsonConvert.DeserializeObject<GameStats>(await ReadFileInAsync(BronzeGameSaveFilePath)),
"silver" => JsonConvert.DeserializeObject<GameStats>(await ReadFileInAsync(SilverGameSaveFilePath)),
_ => null
};
if (gameSave is not null)
{
_GameStats.CurrentGame = gameSave.CurrentGame; // or maybe better create a copy from method
// ...
}
else
{
// todo: throw? clear game stats?
}
}
I am assuming you are using the Newtonsoft JSON converter.
When you deserialize your JSON, the gameSave["CurrentGame"] might be the type of Int64 which can not be directly converted to int since it can store larger values.
You can try to convert it with Convert.ToInt32(gameSave["CurrentGame"]), and you would be probably fine, since I guess your game IDs won't overflow the int.
The next time you run into any problem like this you can check the type of your variable with gameSave["CurrentGame"].GetType().Name and see where it goes wrong.
But as Robert Harvey mentioned, you would be probably better off directly deserializing it into the class you are using.
How about doing this
_GameStats.CurrentGame = (gameSave["CurrentGame"] is int) ? (int)gameSave["CurrentGame"] : _GameStats.CurrentGame;
_GameStats.CurrentWord = (gameSave["CurrentWord"] is int) ? (int)gameSave["CurrentWord"] : _GameStats.CurrentWord;
_GameStats.Score = (gameSave["Score"] is int) ? (int)gameSave["Score"] : _GameStats.Score;
_GameStats.BestScore = (gameSave["BestScore"] is int) ? (int)gameSave["BestScore"] : _GameStats.BestScore;
_GameStats.Difficulty = (gameSave["Difficulty"] is int) ? (int)gameSave["Difficulty"] : _GameStats.Difficulty;
_GameStats.IsNewGame = (gameSave["IsNewGame"] is bool) ? (bool)gameSave["IsNewGame"] : _GameStats.IsNewGame;
_GameStats.IsContinue = (gameSave["IsContinue"] is bool) ? (bool)gameSave["IsContinue"] : _GameStats.IsContinue;
_GameStats.IsUnlocked = (gameSave["IsUnlocked"] is bool) ? (bool)gameSave["IsUnlocked"] : _GameStats.IsUnlocked;
_GameStats.GameVersion = (gameSave["GameVersion"] is string) ? (string)gameSave["GameVersion"] : _GameStats.GameVersion;
_GameStats.Cards = (gameSave["Cards"] is ObservableCollection<LevelCardGroup>) ? (ObservableCollection<LevelCardGroup>)gameSave["Cards"] : _GameStats.Cards;
I'm getting this error on DataBind(), and I don't know why since there shouldn't be anything selected.
DdState.Items.Clear();
DdState.DataSource = UsStates;
DdState.DataTextField = "Title";
DdState.DataValueField = "Title";
DdState.Items.Insert(0, String.Empty);
if (DdState.SelectedItem != null)
{
DdState.SelectedItem.Selected = false;
}
DdState.DataBind();
private IEnumerable<IStateItem> UsStates
{
get
{
var statesFolder = _sitecoreService.GetItem<ISitecoreItem>(ItemReference.BcsUs_ProductData_States.Guid);
if (statesFolder == null)
return new List<IStateItem>();
List<IStateItem> usStates = _sitecoreService.QueryChildren<IStateItem>(statesFolder).OrderBy(s => s.Title).ToList();
return usStates;
}
}
I tried putting in DdState.SelectedIndex = 0 before the DataBind(), but then I got an error that the selected index did not exist. What's going on?
If the DataSource is a list its much easier to implement. So just "convert" the UsStates IEnumerable to a List an then add it to the data source.
DdState.DataSource = UsStates.ToList();
Then choose the property of a list item as binding.
OR
public Form1()
{
InitializeComponent();
DdState.Items.Clear();
DdState.DataSource = UsStates;
DdState.DisplayMember = "Statename";
DdState.SelectedIndex = 0;
}
private List<IStateItem> UsStates
{
get
{
List<IStateItem> usStates = new List<IStateItem>();
usStates.Add(new IStateItem("California","status1"));
usStates.Add(new IStateItem("Ohio", "status3"));
return usStates;
}
}
private class IStateItem
{
public IStateItem(string statename, string stateStatus)
{
Statename = statename;
StateStatus = stateStatus;
}
public string Statename { get; set; }
public string StateStatus { get; set; }
}
Could there be something wrong with your IStateItem class?
I copy/pasted your code in a new asp.net application, made my own IStateItem class and it works.
using System;
using System.Collections.Generic;
namespace TestIt
{
public partial class Form1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FillTheList();
}
private void FillTheList()
{
ddl_TheList.Items.Clear();
ddl_TheList.DataSource = UsStates;
ddl_TheList.DataTextField = "statename";
ddl_TheList.DataValueField = "stateStatus";
//ddl_TheList.Items.Insert(0, String.Empty);
ddl_TheList.DataBind();
ddl_TheList.SelectedIndex = 0;
}
private IEnumerable<IStateItem> UsStates
{
get
{
List<IStateItem> usStates = new List<IStateItem>();
for (int i = 0; i < 10; i++)
{
usStates.Add(new IStateItem { statename = "state #" + i, stateStatus = "cool state bro" });
}
return usStates;
}
}
}
public class IStateItem
{
public string statename { get; set; }
public string stateStatus { get; set; }
}
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
The title is a little prosaic, I know. I have 3 classes (Users, Cases, Offices). Users and Cases contain a list of Offices inside of them. I need to compare the Office lists from Users and Cases and if the ID's of Offices match, I need to add those IDs from Cases to the Users. So the end goal is to have the Users class have any Offices that match the Offices in the Cases class.
To add clarity, I am looking to compare the two officeLists (users.officeList and cases.OfficeList) and when any Cases.OfficeList.ID == Users.OfficeList.ID, I need to add that Case.ID to the list of Users.caseAdminIDList
Any ideas?
My code (which isnt working)
foreach (Users users in userList)
foreach (Cases cases in caseList)
foreach (Offices userOffice in users.officeList)
foreach (Offices caseOffice in cases.officeList)
{
if (userOffice.ID == caseOffice.ID)
users.caseAdminIDList.Add(cases.adminID);
}//end foreach
//start my data classes
class Users
{
public Users()
{
List<Offices> officeList = new List<Offices>();
List<int> caseAdminIDList = new List<int>();
ID = 0;
}//end constructor
public int ID { get; set; }
public string name { get; set; }
public int adminID { get; set; }
public string ADuserName { get; set; }
public bool alreadyInDB { get; set; }
public bool alreadyInAdminDB { get; set; }
public bool deleted { get; set; }
public List<int> caseAdminIDList { get; set; }
public List<Offices> officeList { get; set; }
}
class Offices
{
public int ID { get; set; }
public string name { get; set; }
}
class Cases
{
public Cases()
{
List<Offices> officeList = new List<Offices>();
ID = 0;
}//end constructor
public int ID { get; set; }
public string name { get; set; }
public int adminID { get; set; }
public bool alreadyInDB { get; set; }
public bool deleted { get; set; }
public List<Offices> officeList { get; set; }
}
//in my main method
private bool grabCasesFromAdminDB() //gets cases from DB1 (AdminDB)
{
DatabaseIO dbIO = new DatabaseIO();
caseList = dbIO.getCasesFromAdminDB(adminDBConString, caseList).ToList();
if (dbIO.errorMessage == null || dbIO.errorMessage.Equals(""))
{
if (getCaseOfficeRelationship())
return true;
else
return false;
}//end if
else
{
MessageBox.Show(dbIO.errorMessage, "Admin DB Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}//end else
}//end method
private bool grabCasesFromListDB()//grabs cases from the main db
{
DatabaseIO dbIO = new DatabaseIO();
caseList = dbIO.getCasesFromMainDB(connectionString, caseList).ToList();
if (dbIO.errorMessage == null || dbIO.errorMessage.Equals(""))
return true;
else
{
MessageBox.Show(dbIO.errorMessage, "Main DB Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}//end else
}//end method
private bool getCaseOfficeRelationship()//adds office relationship to cases
{
DatabaseIO dbIO = new DatabaseIO();
caseList = dbIO.getOfficeToCaseRelationship(connectionString, caseList).ToList();
if (dbIO.errorMessage == null || dbIO.errorMessage.Equals(""))
{
if (getOfficeNamesByID())
return true;
else
return false;
}//end if
else
{
MessageBox.Show(dbIO.errorMessage, "Cases To Offices Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}//end else
}//end method
private bool getOfficeNamesByID()//grabs the id of the offices by name
{
List<Offices> officeList = new List<Offices>();
DatabaseIO dbIO = new DatabaseIO();
officeList = dbIO.getOfficeNamesByOfficeID(connectionString).ToList();
if (dbIO.errorMessage == null || dbIO.errorMessage.Equals(""))
{
matchOfficeNamesToIDs(officeList);
return true;
}//end if
else
{
MessageBox.Show(dbIO.errorMessage, "Getting Office List Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}//end else
}//end method
private void matchOfficeNamesToIDs(List<Offices> officeList)
{
foreach (Cases cases in caseList)
if (cases.officeList != null)
foreach (Offices office in cases.officeList)
{
foreach (Offices innerOffice in officeList)
if (innerOffice.ID == office.ID)
office.name = innerOffice.name;
}//end foreach
}//end method
//an example of my DBIO class
public List<Cases> getCasesFromAdminDB(string adminDBConString, List<Cases> caseList)
{
try
{
Cases cases = null;
SqlConnection con = new SqlConnection();
con.ConnectionString = adminDBConString;
con.Open();
SqlCommand command = new SqlCommand();
command.Connection = con;
command.CommandText = "select CS_Case_ID, Case_Name from CS_Case where CS_Product_Type_ID = 2 and CS_Case_Status_ID = 1";
SqlDataReader thisReader = command.ExecuteReader();
int idxID = thisReader.GetOrdinal("CS_Case_ID");
int idxName = thisReader.GetOrdinal("Case_Name");
while (thisReader.Read())
{
bool found = false;
foreach (Cases tempCase in caseList)
{
if (tempCase.adminID == Int32.Parse(thisReader.GetValue(idxID).ToString()))
{
tempCase.alreadyInDB = true;
found = true;
}//end if
}//end foreach
if (!found)
{
cases = new Cases();
cases.adminID = Int32.Parse(thisReader.GetValue(idxID).ToString());
cases.name = thisReader.GetValue(idxName).ToString();
cases.alreadyInDB = false;
cases.officeList = new List<Offices>();
caseList.Add(cases);
}//end if
}//end while
thisReader.Close();
return caseList;
}//end try
catch (Exception excep1)
{
errorMessage = "Cases could not be loaded from the Admin Console." + "\r\n" + "Error message: " + excep1.ToString();
return caseList;
}//end catch
}//end method
Complex querying like this is best handled by LINQ. If you had a common element on both Users and Cases, then this would be a job for a join. But in this case instead of a common element, they each contain lists, and you want to "join" on those where the two lists have a common element.
So, to start off, what's the condition for a particular case to be included for a user?
case.officeList.Any(caseOffice => user.officeList.Any(userOffice => caseOffice.ID == userOffice.ID))
i.e. Any office in the case's officeList is contained in the user's officeList.
Now we have that condition, we can use it in a LINQ Where clause to pull out all the desired case:
caseList.Where(case =>
case.officeList.Any(caseOffice => user.officeList.Any(userOffice => caseOffice.ID == userOffice.ID)))
That returns our collection of cases, so finally we just want to Select out the part of the case we need, the adminID.
caseList.Where(case =>
case.officeList.Any(caseOffice => user.officeList.Any(userOffice => caseOffice.ID == userOffice.ID)))
.Select(case => case.adminID);
So putting that all together:
foreach(Users users in userList)
{
users.caseAdminIDList = caseList.Where(case =>
case.officeList.Any(caseOffice => user.officeList.Any(userOffice => caseOffice.ID == userOffice.ID)))
.Select(case => case.adminID).ToList();
}
public Cases()
{
List<Offices> officeList = new List<Offices>();
ID = 0;
}//end constructor
This is making a new varaible called officeList. It will not use the officeList outside the constructor.
This needs to be changed to:
officeList = new List<Offices>();
This will properly initialize the class field.
You can implement your Offices class like this:
class Offices:IEquatable<Offices>
{
public int ID { get; set; }
public string name { get; set; }
public bool Equals(Offices other)
{
return this.ID.Equals(other.ID);
}
public override int GetHashCode()
{
return this.ID.GetHashCode();
}
}
Then in your code to have the Users class have any Offices that match the Offices in the Cases class just do this;
usersVariable.CaseAdminIDList = usersVariable.OfficeList.Intersect(casesVariable.OfficeList).Select(o => o.ID).ToList();
Also in your users and cases class you need to initialize the list properly(you are using automatic properties and in ctor declaring and initializing a whole new variable),something
like this for example:
class Users
{
public Users()
{
officeList = new List<Offices>();
caseAdminIDList = new List<int>();
ID = 0;
}//end constructor
private List<Offices> officeList;
public List<Offices> OfficeList
{
get { return officeList; }
set { officeList = value; }
}
private List<int> caseAdminIDList;
public List<int> CaseAdminIDList
{
get { return caseAdminIDList; }
set { caseAdminIDList = value; }
}
//other members.....
}
I have a class, which is created and populated from an xml string, I've simplified it for example purposes:
[XmlRoot("Person")]
public sealed class Person
{
[XmlElement("Name")]
public string Name { get; set; }
[XmlElement("Location")]
public string Location { get; set; }
[XmlElement("Emails", Type = typeof(PersonEmails)]
public PersonEmails Emails { get; set; }
}
public class PersonEmails
{
[XmlElement("Email", Type = typeof(PersonEmail))]
public PersonEmail[] Emails { get; set; }
}
public class PersonEmail
{
[XmlAttribute("Type")]
public string Type { get; set; }
[XmlText]
public string Value { get; set; }
}
To extract the information, I'm trying to load them into another class, which is simply:
public class TransferObject
{
public string Name { get; set; }
public ObjectField[] Fields { get; set; }
}
public class ObjectField
{
public string Name { get; set; }
public string Value { get; set; }
}
I'm only populating "Fields" from the other object, which would simply be (Name = "Location", Value = "London"), but for Emails, (Name = "Email"+Type, Value = jeff#here.com)
Currently I can populate all the other fields, but I'm stuck with Emails, and knowing how to dig deep enough to be able to use reflection (or not) to get the information I need. Currently I'm using:
Person person = Person.FromXmlString(xmlString);
List<ObjectField> fields = new List<ObjectField>();
foreach (PropertyInfo pinfo in person.getType().GetProperties()
{
fields.Add(new ObjectField { Name = pinfo.Name, Value = pinfo.getValue(person, null).ToString();
}
How can I expand on the above to add all my emails to the list?
You are trying to type cast a complex values type to string value so you lost the data. Instead use following code:
class Program
{
static void Main(string[] args)
{
Person person = new Person();
person.Name = "Person One";
person.Location = "India";
person.Emails = new PersonEmails();
person.Phones = new PersonPhones();
person.Emails.Emails = new PersonEmail[] { new PersonEmail() { Type = "Official", Value = "xyz#official.com" }, new PersonEmail() { Type = "Personal", Value = "xyz#personal.com" } };
person.Phones.Phones = new PersonPhone[] { new PersonPhone() { Type = "Official", Value = "789-456-1230" }, new PersonPhone() { Type = "Personal", Value = "123-456-7890" } };
List<ObjectField> fields = new List<ObjectField>();
fields = GetPropertyValues(person);
}
static List<ObjectField> GetPropertyValues(object obj)
{
List<ObjectField> propList = new List<ObjectField>();
foreach (PropertyInfo pinfo in obj.GetType().GetProperties())
{
var value = pinfo.GetValue(obj, null);
if (pinfo.PropertyType.IsArray)
{
var arr = value as object[];
for (var i = 0; i < arr.Length; i++)
{
if (arr[i].GetType().IsPrimitive)
{
propList.Add(new ObjectField() { Name = pinfo.Name + i.ToString(), Value = arr[i].ToString() });
}
else
{
var lst = GetPropertyValues(arr[i]);
if (lst != null && lst.Count > 0)
propList.AddRange(lst);
}
}
}
else
{
if (pinfo.PropertyType.IsPrimitive || value.GetType() == typeof(string))
{
propList.Add(new ObjectField() { Name = pinfo.Name, Value = value.ToString() });
}
else
{
var lst = GetPropertyValues(value);
if (lst != null && lst.Count > 0)
propList.AddRange(lst);
}
}
}
return propList;
}
}
Check this snippet out:
if(pinfo.PropertyType.IsArray)
{
// Grab the actual instance of the array.
// We'll have to use it in a few spots.
var array = pinfo.GetValue(personObject);
// Get the length of the array and build an indexArray.
int length = (int)pinfo.PropertyType.GetProperty("Length").GetValue(array);
// Get the "GetValue" method so we can extact the array values
var getValue = findGetValue(pinfo.PropertyType);
// Cycle through each index and use our "getValue" to fetch the value from the array.
for(int i=0; i<length; i++)
fields.Add(new ObjectField { Name = pinfo.Name, Value = getValue.Invoke(array, new object[]{i}).ToString();
}
// Looks for the "GetValue(int index)" MethodInfo.
private static System.Reflection.MethodInfo findGetValue(Type t)
{
return (from mi in t.GetMethods()
where mi.Name == "GetValue"
let parms = mi.GetParameters()
where parms.Length == 1
from p in parms
where p.ParameterType == typeof(int)
select mi).First();
}
You can definately do it with Reflection... You can take advantage of the fact that a Type can tell you if it's an array or not (IsArray)... and then take advantage of the fact that an Array has a method GetValue(int index) that will give you a value back.
Per your comment
Because Emails is a property within a different class, recursion should be used. However the trick is knowing when to go to the next level. Really that is up to you, but
if it were me, I would use some sort of Attribute:
static void fetchProperties(Object instance, List<ObjectField> fields)
{
foreach(var pinfo in instance.GetType().GetProperties())
{
if(pinfo.PropertyType.IsArray)
{
... // Code described above
}
else if(pinfo.PropertyType.GetCustomAttributes(typeof(SomeAttribute), false).Any())
// Go the next level
fetchProperties(pinfo.GetValue(instance), fields);
else
{
... // Do normal code
}
}
}
I have this LINQ statement that tries to set the 1st element in the collection of string[]. But it doesn't work.
Below is the LINQ statement.
docSpcItem.Where(x => x.DocID == 2146943)
.FirstOrDefault()
.FinishingOptionsDesc[0] = "new value";
public string[] FinishingOptionsDesc
{
get
{
if (this._FinishingOptionsDesc != null)
{
return (string[])this._FinishingOptionsDesc.ToArray(typeof(string));
}
return null;
}
set { this._FinishingOptionsDesc = new ArrayList(value); }
}
What's wrong with my LINQ statement above?
Couple of things.. There are some problems with your get and set. I would just use auto properties like this..
public class DocSpcItem
{
public string[] FinishingOptionsDesc { get; set; }
public int DocID { get; set; }
}
Next for your linq statement, depending on the presence of an item with an id of 2146943 you might be setting a new version of the object rather than the one you intended. This should work..
[TestMethod]
public void Linq()
{
var items = new List<DocSpcItem>();
//2146943
for (var i = 2146930; i <= 2146950; i++)
{
items.Add(new DocSpcItem()
{ DocID = i
, FinishingOptionsDesc = new string[]
{ i.ToString() }
}
);
}
var item = items.FirstOrDefault(i => i.DocID == 2146943);
if (item != null)
{
item.FinishingOptionsDesc = new string[]{"The New Value"};
}
}
and
public class DocSpcItem
{
public string[] FinishingOptionsDesc { get; set; }
public int DocID { get; set; }
}