|
Thanks Luc. Yes, I could just iterate through the dictionary and populate the listbox but my concern is that I would be exposing the 'master' collection to the form. From an abstraction point of view I was trying to avoid this and only allowing a method (parkinglot.displayitems) to output the contents of the dictionary in a read only form (currently a string that is formatted ready to just display in the textbox)... this is where I've now got confused! Do I just return a copy of the dictionary from this method or some other collection (which I can then iterate through or bind to), or do I just expose the master dictionary object? I'm trying to follow/show good design practices with this project :-/
|
|
|
|
|
When you return a collection of objects basically it is an array of pointers. Making the collection read-only protects the array, not its elements (the objects it refers to). So whatever you do, as long as you export instances of Vehicle, they become public and modifiable.
There are two ways to remedy this:
1. Create and export a deep copy: build a new collection with copies of your Vehicles. Now if Vehicle contains references (say to a Manufacturer class), then these objects must be deep copied too. That soon gets very cumbersome.
2. Create and export exactly the information you need, in a data structure that isn't otherwise used in your ParkingLot class. In this case that would be a list of strings. And then you should create this data each time it is requested, you should not store it inside ParkingLot and just pass a pointer, as then one client could still falsify the information another client gets.
Either way, the clean approach is to provide a ParkingLot property or method that creates and returns the information required; and then you can use that any way you want, no harm can be done to the ParkingLot.
The one thing you probably would also need is a way to signal the outside world your ParkingLot has changed. An event seems appropriate here.
|
|
|
|
|
Ah, yes, of course they are. Completely forgot it just stores pointers to the objects. Thanks for pointing that out!!
As I said, it's been a while! Thanks for your help 
|
|
|
|
|
You're welcome.
|
|
|
|
|
Personally I would use a List<vehicle> and binding, but then I use WPF not winforms. I find List<> to much more maintainable and manageable.
I would also not allow database/binding or list/dictionary efficiency to influence my decision with such a small number if items.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Performance is not an issue, even with thousands of dictionary entries.
Your "parking lot" class is in effect your "data repository", and you can use a similar pattern for that. Ultimately, your "backing store" may be be XML or a data base; if a "client" needs a "list", they get a list; if they want to "empty" a parking spot, there's a method for that, etc. The client doesn't care what the backing store looks like, it just wants what it needs.
And as Luc pointed out, it's all references to existing objects unless you're cloning.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
modified 5-Apr-20 17:11pm.
|
|
|
|
|
I would suggest you model a "parking lot business:"
PLotBusiness
Finances ?
PLotData : map vehicles to locations, status, etc.
VehicleManager
Cars
Vans
PLotManager
Spaces I would use methods in these classes that returned collections, or datatables, for binding to Controls as necessary.
imho, the separation of concerns in this model is desirable. "Let the atoms remain ignorant of how they are used in molecules," I once said
for UI design, think about the end-user: their technical depth, their role, their needs, security ...
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Expose a Cars property:
public IEnumerable<Vehicle> Cars { get { return _dictionary.Values; } }
(This assumes:
private Dictionary<string, Vehicle> _dictionary; )
Bind parkingLot.Cars to your listbox.
Make sure Vehicle has a ToString() which renders it as you want it to appear in the listbox.
Truth,
James
|
|
|
|
|
Hello friends. I have a big problem..
Know about C# FlowLayoutPanel Controls how to filter sql query use? 
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
So typing as little as possible help no-one - we don't even know what kind of app you are writing, so we can't give you any specific information!
Try again, this time explaining as if to someone who knows absolutely nothing about your project and is at the other end of a telephone.
Tell us what you have tried, where you are stuck, what help you need - and be specific!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
FlowLayoutPanel has absolutely nothing to do with filtering records. All it does is affect how contained controls are laid out on the form.
|
|
|
|
|
Unable to see traces and Service in Jaeger UI on host server, used C# client (tracer) for Jaeger but able see traces in local environment using "jaeger-all-in-one --collector.zipkin.http-port=9411"
I have tried below code and Referred link as
https://itnext.io/jaeger-tracing-on-kubernetes-with-asp-net-core-and-traefik-86b1d9fd5489
public static class JaegerTracingServiceCollectionExtensions
{
public static IServiceCollection AddJaegerTracing(
this IServiceCollection services,
Action<jaegertracingoptions> setupAction = null)
{
if (setupAction != null) services.ConfigureJaegerTracing(setupAction);
services.AddSingleton<itracer>(cli =>
{
var options = cli.GetService<ioptions<jaegertracingoptions>>().Value;
var senderConfig = new Jaeger.Configuration.SenderConfiguration(options.LoggerFactory)
.WithAgentHost(options.JaegerAgentHost)
.WithAgentPort(options.JaegerAgentPort);
var reporter = new RemoteReporter.Builder()
.WithLoggerFactory(options.LoggerFactory)
.WithSender(senderConfig.GetSender())
.Build();
var sampler = new GuaranteedThroughputSampler(options.SamplingRate, options.LowerBound);
var tracer = new Tracer.Builder(options.ServiceName)
.WithLoggerFactory(options.LoggerFactory)
.WithReporter(reporter)
.WithSampler(sampler)
.Build();
// Allows code that can't use dependency injection to have access to the tracer.
if (!GlobalTracer.IsRegistered())
GlobalTracer.Register(tracer);
return tracer;
});
services.AddOpenTracing(builder => {
builder.ConfigureAspNetCore(options => {
options.Hosting.IgnorePatterns.Add(x => {
return x.Request.Path == "/health";
});
options.Hosting.IgnorePatterns.Add(x => {
return x.Request.Path == "/metrics";
});
});
});
return services;
}
public static void ConfigureJaegerTracing(
this IServiceCollection services,
Action<jaegertracingoptions> setupAction)
{
services.Configure<jaegertracingoptions>(setupAction);
}
}
|
|
|
|
|
So what exactly is your question?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Dear All,
I am beginner in C# and I am building an application to create a workbook (Book1.xlsx) then copy a specific sheet from another workbook ( Book2.xlsx ).
I created Book1 but I am trying to copy Sheet1 from Book2 but I could not.
before copying [Sheet1 from Book2 ] I am dong a kind of check to collect names for all opened workbooks so I could not be able to get names of workbooks which opened by Visual Studio c# by the below piece of code but If will open the same workbooks by myself I found the below code can get the name of opened workbooks without problem.
I don't know why.
public void CopyAsiRefSheet()
{
Microsoft.Office.Interop.Excel.Application XAPP;
XAPP = (Microsoft.Office.Interop.Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
foreach (Microsoft.Office.Interop.Excel.Workbook WB in XAPP.Workbooks)
{
MessageBox.Show(WB.Name);
}
}
Thanks,
Moelsayed
|
|
|
|
|
|
I`m working on a graphics editor. I was trying to implement a gui in DirectX but I realised that`s not the right approach. I`m used to C# Forms so I was asking myself if I can stitch C# GUI (Forms) and C++ DirectX together. Any help is welcome.
|
|
|
|
|
WinForms is also not the right approach. Use WPF instead.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Could you expand? I would like to use my existing C++ code base would that be possible?
|
|
|
|
|
That's impossible to answer since you are the only one who knows how that code is written and what it depends on.
|
|
|
|
|
|
Ok, Thanks [edit] all C solution is probably what I`m looking for.
modified 2-Apr-20 5:13am.
|
|
|
|
|
Dear People!
I need a usable license plate recognition program for my thesis. I would like to use it for entry access control. I wrote my program in C# language and the recogniser should be detect plate from images. I really appreciate any help or suggestion.
I want to detect europen plates, especially Hungarian and area.
Can you help me?
Thank you for your help!
|
|
|
|
|
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...
A very quick search gave over half a million hits: detect european number plates c - Google Search[^]
Start there, and begin reading.
In future, please try to do at least basic research yourself, and not waste your time or ours.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi Dear,
I was writing on unit test using Nunit, and suddenly one question came in my mind. So my Unit test are beloe:
[TestMethod]
public void TestMethod()
{
string input ="1,2";
int output =3;
Add add= new Add();
var result= add.GetSum(input);
Assert.AreEqual(output, result);
}
Now my query is when we are defining any variable using string or int it will allocate some memory in heap or stack. So will that memory get de-allocated after completion of unit test?
OR What if will not define variables and pass values directly in Assert like below:
[TestMethod]
public void TestMethod()
{
Add add= new Add();
var result= add.GetSum("1,2");
Assert.AreEqual(3, result);
}
So what is the difference between both the unit tests in terms of performance and memory management?
Thanks
|
|
|
|
|
User-8621695 wrote: will that memory get de-allocated after completion of unit test? Yes, since the scope of the variables is restricted to the test methods, they will be deallocated on return from the method.
|
|
|
|