[Solved] C# – optimize logic [closed]

Your question is not well-phrased. If your elem1 or elem2 is a single item you want to compare against, this is pretty easy. Just do a LINQ Where to find the items that match the criteria. Coordinates it = new Coordinates { lat = 5, lon = 5 }; var picked = list.Where(x => Math.Abs(x.lat … Read more

[Solved] How to name a file using a value in a list in a dictionary?

Something like this: dictionary = {‘results’: [{‘name’: ‘sarah’, ‘age’: ’18’}]} name = dictionary[‘results’][0][‘names’] + ‘.txt’ open(name, “w”) Opening a file in the write mode, if it doesn’t exist already, will create a new file with that name. 2 solved How to name a file using a value in a list in a dictionary?

[Solved] Python: Unhashable error, lists

Two major issues: 1) You are storing the results in chos_items, then not doing anything with them. full_items, when you exit the while loop, contains “end” or “” print(“That would be, {}”.format(‘ ‘.join([items[int(item)] for item in chos_items]))) Will give you a list of all the items chosen, but it won’t give how many, as you … Read more

[Solved] New Value not added to list (C#)

UPDATED: private List<string> Clients = new List<string>(){ “Jack”, “Sandra”, “Anna”, “Tom”, “Bob”}; private void btnAddClient_Click(object sender, EventArgs e) { string msg = “”; if (txtAddClient.Text == “”) { MessageBox.Show(“No client name has been entered!”); } else { string newClient = txtAddClient.Text; Clients.Add(newClient); foreach (string val in Clients) { msg += “- ” + val + … Read more

[Solved] C# code for open/close drawer and printing the receipt at the same time? [closed]

using System; using System.Collections.Generic; using System.Text; using Microsoft.PointOfService; namespace POS { public class CashDrawerClass { CashDrawer myCashDrawer; PosExplorer explorer; public CashDrawerClass() { explorer = new PosExplorer(this); DeviceInfo ObjDevicesInfo = explorer.GetDevice(“CashDrawer”); myCashDrawer = explorer.CreateInstance(ObjDevicesInfo); } public void OpenCashDrawer() { myCashDrawer.Open(); myCashDrawer.Claim(1000); myCashDrawer.DeviceEnabled = true; myCashDrawer.OpenDrawer(); myCashDrawer.DeviceEnabled = false; myCashDrawer.Release(); myCashDrawer.Close(); } } } try that. maybe … Read more

[Solved] How do I manipulate an object’s properties after it has been added to a List in C#

You can get the first item of the list like so: Person p = pList[0]; or Person p = pList.First(); Then you can modify it as you wish: p.firstName = “Jesse”; Also, I would recommend using automatic properties: class public Person { public string firstName { get; set; } public string lastName { get; set; … Read more

[Solved] Java List not contains object [closed]

Your attempt won’t work since you’re handling the creation in the loop, so you will end up adding several persons there. Just write it the way you described it: if (allPersons.isEmpty() || !allPersons.contains(person)) allPersons.add(person) Now, in order for this to work you have to ask yourself an important question: What exactly constitutes “the same person”? … Read more

[Solved] How to break from the loop when adding values to the list object which is distinct from already added values of the list?

You can use Contains status = false; for (var i = 0; i < ids.Count; i++) { if (list.Count > 0 && !list.Contains(ids[i])){ list.Add(ids[i]); //add this, be it duplicate or not status = true; //different element found break; //break if this is not duplicate } else { //do something for duplicate list.Add(ids[i]); //add this, be … Read more