OK, I cannot get my head around the whether there is a difference between the 'classic' (perhaps long winded) way of doing it, multiple classes and the 'new' Yield route to (apparently) the same end.
I can understand the classic route (I think), see the code below.
Yield confuses the heck out of me, if I understand it correctly then it's absolutely genius, I get the idea of a state machine (I think) and logically it sort of makes sense but I am not at all confident.
Can it possibly be this simple? You just make that one method as simple or complex as necessary for your situation? (Warning, silly example since arrays can already be enumerated, but it's easy to demo)
Private _Thing AsDouble()
Public Iterator Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
If IsNothing(Me._Thing) ThenThrowNew InvalidOperationException()
EndIfFor Index AsInteger = 0ToMe._Thing.GetUpperBound(0)
What I understand to be the 'old way'.
Private _Thing AsDouble()
PublicFunction GetEnumerator() As IEnumerator(OfDouble) Implements IEnumerable(OfDouble).GetEnumerator
EndFunctionPublicFunction GetEnumerator1() As IEnumerator Implements IEnumerable.GetEnumerator
Private _Thing AsDouble()
Private _Index AsIntegerPrivate _curItem AsDoublePublicSubNew(ByVal Thing AsDouble())
Me._Thing = Thing
Me._Index = -1
Me._curItem = NothingEndSubPublicReadOnlyProperty Current AsDoubleImplements IEnumerator(OfDouble).Current
GetIf IsNothing(Me._curItem) ThenThrowNew InvalidOperationException()
EndGetEndPropertyPublicReadOnlyProperty Current1 AsObjectImplements IEnumerator.Current
EndGetEndPropertyPublicFunction MoveNext() AsBooleanImplements IEnumerator.MoveNext
'If we are already at the end then return false
IfMe._Index = Me._Thing.GetUpperBound(0) ThenReturnFalseEndIf'Otherwise move to the next position in the array
Me._Index += 1Me._curItem = Me._Thing(Me._Index)
ReturnTrueEndFunctionPublicSub Reset() Implements IEnumerator.Reset
Me._Index = -1
Me._curItem = NothingEndSub#Region"IDisposable Support"EndClass
I realise this is a late answer, so maybe you've already figured this out. But maybe it's still worth something, so here goes:
I think the short answer is that Yield is absolutely genius. The 'classic' way as you put it actually is the same implementation over and over again, where only the return value varies. What yield does for you is that it allows you to construct an IEnumerable directly from a function (using Yield statements), such that every time MoveNext() is called, the function takes off where it left off until the next Yield statement.
So, yes, you can just use yield whenever you want I think the only possible issue with it is that it's probably slower than a proper custom ('classic') implementation, so if you have A LOT of elements AND you notice a performance bottleneck in enumeration THEN you might consider getting your hands dirty.
I'm just writing some instructions for installing a .NET COM component.
The first steps are to use regasm and gacutil, but these don't seem to be distributed with the actual framework, and you need to use a version that matches your .NET v or above (i.e. can't use a v2 regasm with a v4 dll).
So I want to say where you can get a copy from, but what 'package' contains these to components? is it the .NET or Windows SDKs?
I'm developing a web tool and I started using asp.net with c# ,, an important part of the code is already written in c++ , I was looking and searching around and I kind of understood that I can use c++ as the web development language. Is this true ?
this is my first time developing a web tool, sorry
It's a royal pain in the ass, but it can be done. You have to use Managed C++ (C++/CLI), but it can be done. There are no ASP.NET templates so you have to write every tiny bit of code and wire up everything yourself.
It's really not worth the pain. You're not getting that much of a performance bost to make it worth the trouble. If there are critical pieces of code that must be hand optimized, then you can write your critical code into components and use those in the C# or VB.NET code for the site.
I played around with it some time back and it looked pretty promising.
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore, Dream. Discover.
I did configure the Symbol LS3408 scanner to be a USB scanner, not a keyboard.
This was not my question. The question was, if anyone has made some C# code, that gets the reading from an USB barcode scanner. I know there are solutions out there, where you get the reading as a keyboard input. I don't want that.
Your best bet would be to download the Scanner SDK from here[^]. Using someone else's code is going to be problematic at best as their code is going to make assumptions about the scanner that do no apply to your situation.
i have a listview control in my winRT application and, when the user taps a tile, i´d like to save the previously selectedIndex.
i can´t find an appropriate eventhandler to achieve this;
i only found SelectionChanged-event, but, as one might guess, at this particular time the Event is already fired and i retrieve only the new selected index...
can anyone please Point me to the right direction... eh, to the right Event ?
and - if someone knows where to get an elaborated overview for the LifeCycle - as known form ASP.NET pages - that would be highly appreciated...
Hmm... Can you just look for a similar event in the XAML-control?
Another solution could be that you have a second variable where your current index is stored... You would have to update this variable manually and it would end up kinda unclean but this could be the emergency-solution.
sorry for replying late....
first of all: thank you for your help.
I´ve found several events (ItemClick, Tapped etc) but none of them seem to suit.
your second suggestion leads me back to my initial question:
where to save the old index...?
I wonder what the softie´s intention was when they decided not to implement a SelectedIndex_Changing in addition to SelectedIndex_Changed.
that would solve the issue perfectly...
That´s also a good idea, but I have already solved the problem, I think, I´ll leave it at that.
it now works the way it should, that´s sufficient for me!
Thank you again for your help!
ok, finally I got it...
it´s more like right through the chest into the eye, but now it works...
a healthy mixture of ListView.SelectedIndex_Change and Grid.GotFocus did the trick for me; now I can save the old AND the new index....
thanks to marco for his suggestions!
I can´t find the checkbox for marking my thread as solved...
I guess i´m blind...
Greetings all - I haven't posted here in ages I am entirely new to .Net having been working in it for a week at most so please go easy and be detailed as possible
I have the following PONO:
Private intTrackingNumber AsIntegerPrivate intDateReceived AsIntegerPrivate strManufacturer AsStringPublicProperty TrackingNumber() AsIntegerGetReturn intTrackingNumber
intTrackingNumber = value
EndSetEndPropertyPublicProperty DateReceived() AsStringGet' TODO: Convert timestamp to formatted date
' TODO: Convert formatted date to timestamp
intDateReceived = value
The issue I am faced with is how to store date/time as a timestamp (integer) but provide public properties which format/convert accordingly.
I suppose I could provide a an additional getter()/setter() but ideally I wonder if EF has a way of circumventing this "convention"?
Additionally - I am also curious as to whether it's possible to map properties to columns which are not labeled correctly?
Basically if I were working in a existing database (EF automatically builds my PONO with properties named after table fields) I wish to name the fields something more meaningful; some fields for example might be awkward abbreviations but in the object model I want something more English friendly?
I seem to recall being able to do this with Hibernate in java (actually it's PHP port) but never the less does EF support such a feature? Seems obvious that this would be useful in day to day development???
I just found some articles that explain how to change the mapping for tables so I imagine columns are just around the corner.
When I say timestamp I mean a unix timestamp which can easily be converted to date AND/OR time - not sure what MSDN is getting at?!?
In the database I wish to store the date "10/10/2013" as 1381381200 but convert to a human friendly date within the PONO.
My entity objects are high level abstractions but I still prefer to store the time in a numeric format - how does EF solve/address this type mis-match? This is/was the impetus behind OR/M frameworks ain't it?
Ah, OK - "timestamp" in SQL is something totally different.
I don't think there's any built-in way to perform this sort of conversion in the mapping layer. The simplest approach is probably to add a calculated property for the date, decorated with the NotMapped attribute:
EF will see a .NET type of DateTime in your POCO and use the native DateTime datatype specified by the underlying data provider. It will not convert a DateTime to a "serial number" as you want because the serial number can be based on any arbitrary epoch. For example, UNIX uses 1/1/1970 00:00:00AM whereas .NET uses 1/1/0001 00:00:00AM. So, to each system, the datetime serial number will mean something different.
Why even do this?? Why not just let the underlying database handle the storage and return the correct datetime without your code having to worry about conversion?
Please, I really need a help.
Everytime I try to launch every Kinect application, VS 2010 indicates me that there is a problem with the Runtime in Microsoft.Research.Kinect.
Everytime, I get this :
"Impossible de charger le fichier ou l'assembly 'INuiInstanceHelper, Version=126.96.36.199, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ou une de ses dépendances. Le fichier spécifié est introuvable."
Please, can you tell me what's wrong and what I have to do.
It means that it cannot find the assembly named in the message, or some other assembly that INuiInstanceHelper depends on. Check that you have the correct version of .NET installed and any third party products that are needed.