Page 2 of 4
X# Example Project for various DotNet functionality
Posted: Wed Aug 25, 2021 5:03 pm
by ic2
Hello Volkmar,
VR wrote:Some of the examples use features from the latest x# compiler. I'll add that info in to the readme.
As a quick fix, you can delete the folders, that contain files with errors.
Yes, now can I start the (remaining) various options by uncommenting them from the Program.prg. Very useful.
I should of course update my X# but I haven't used any of the additions not already present in Vulcan and I am always inclined to keep using something that works until I find some new option that I really welcome. That saves compiler errors in newer versions and DLL updates at clients, in the case of X#, and more than once septs back in other program's updates.
But maybe I find something useful in your samples, when reloading, which requires 2.8.
One quick question: I never used a Dictionary. Do you agree with me that you can do the same thing with a List but only slightly shorter?
Code: Select all
List<Part> parts = new List<Part>();
parts.Add(new Part() { PartName = "chain ring", PartId = 1334 });
int index parts.Find(x => x.PartId.Contains("1334")));
? parts[index].PartName
I saw I did once create a Github account and I've given your post 5 stars too.
Dick
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 4:04 am
by wriedmann
Hi Dick,
a list and a dictionary are two different things (ok, a dictionary is a somewhat specialized form of a list).
First of all, a dictionary is not simple a list, but has unique keys and attributed values.
The great thing is that you can access dictionary values using the key like an array index.
Please look here:
https://www.tutorialsteacher.com/csharp ... dictionary
Of course, the value of a dictionary element can be every class, but beware that the keys are unique and not every character is accepted for the key value.
Wolfgang
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 6:03 am
by VR
Hello Dick,
as Wolfgang already described, a dictionary is a specialized data structure. One key difference is, that searching in a list takes O(n) while searching in a dictionary takes O(1). That means, that searching in a list gets slower, when more elements are added to the list, while it stays "the same" for dictionaries.
Here you can find more info on list vs dictionary:
http://net-informations.com/faq/general ... y-list.htm
Volkmar
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 6:17 am
by Chris
To add to what Wolfgang and Volkmar said, for 10 or 20 items, it's probably better just using a List. But if you need a large amount of items and speed of search is important, then a Dictionary is EXTREMELY faster than a List. A SortedList is somewhere in between a List and a Dictionary regarding searching performance.
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 10:10 am
by Karl-Heinz
Hi Volkmar
very nice work !
maybe you could add to your EmumExamples class the possibilty to identify an Answer enum member by a string value.
Code: Select all
// Get the corresponding Answer enum member from the string "NO"
IF Enum.TryParse( "NO" , TRUE, OUT MyAnswer )
WriteEnum(MyAnswer)
ENDIF
btw. you have one more star click
regards
Karl-Heinz
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 10:27 am
by robert
Volkmar,
May I add a suggestion:
If you change the code for the Invoicebuilder to return
instead of List<Invoice>
and then remove the result variable
and instead of adding the Invoices to the list use
and replace the last line of the method with
Then you can really show that Linq delays the creations of the elements in the collection until the last moment and you're not even creating a List.
Robert
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 11:33 am
by ic2
Hello Volkmar, Chris, Wolfgang,
Ok, good to know, thanks. Conclusion: using a dictionary instead of a list makes coding slightly shorter but performance, with many elements, much higher.
If there would be no real advantages it is easier to stick to less options instead of using them all which will also take more time to look up how they are supposed to work. .Net is not very consistent in how to use functions/methods/classes; properties basically doing the same are called different throughout them and therefor as a programmer you will need to do more lookup work for not often used functions.
Dick
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 12:36 pm
by FFF
the other way round: if your "list" is LONG, Dictionary is a LOT faster...
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 1:15 pm
by HansjoergP
It is also a lot easier to get an element with the key and not to search for the index and than get the element.
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 2:47 pm
by ArneOrtlinghaus
I am also using the examples from my colleague Volkmar to adopt some new programming techniques - it is not so simple to leave over 20 years of programming behind.
I am also trying to use methods of the standard types like strings instead of using the VO functions. Of course nothing is gratis - when having index variables as in string.substring, counting starts from 0 and not from 1...
local i as int
local c := "xyz" as string
for i := 1 upto c.Length
cx := c.Substring(i-1, 1)
...
Arne