|
you're really too generous.
|
|
|
|
|
I think the Take extension method of IEnumerable can be used for this purpose as shown below:
List<int> data = new List<int>(){1,2,3,4,5,6,7,8,9,10};
int[] array = data.Take(5).ToArray();
The Take method takes specified number of elements or the total elements of the list if the total is less than the specified number.
|
|
|
|
|
Best answer!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
so far, yes.
|
|
|
|
|
list items have a index, you can use for for selecting 100 item, or if you looking at some value in items use list.Where(p => p.StartsWith("s")) in a Foreach loop.some thing like this:
List<string> lsi = new List<string>();
lsi.Add("sara");
lsi.Add("soo");
lsi.Add("kabab");
foreach (var item in lsi.Where(p => p.StartsWith("s")))
{
Response.Write(item);
}
|
|
|
|
|
With all the upvoted answers so far, you haven't gotten the proper solution yet IMO; I recommend
int[] mySmallArray=myList.GetRange(startIndex, count).ToArray();
which avoids both a big intermediate array and any visible looping, and doesn't require .NET version 3.5+
|
|
|
|
|
You sir, are too modest.
Luc Pattyn wrote: and any visible looping
Way to cover your ass!
Curiously, I'll have to dig into the GetRange code now...
|
|
|
|
|
I'm sure you'll find a loop inside, as well as inside List.ToArray() and Array.Copy() .
And even if List.GetRange() were returning an IEnumerable rather than a list, there still would be a loop doing the hard work.
|
|
|
|
|
I've just seen this and happened to have reflector open so I've had a look!
GetRange uses Array.Copy to copy to a new list:
List<T> list = new List<T>(count);
Array.Copy(this._items, index, list._items, 0, count);
list._size = count;
return list;
as is ToArray but to an array instead:
T[] destinationArray = new T[this._size];
Array.Copy(this._items, 0, destinationArray, 0, this._size);
return destinationArray;
Now quite what Array.Copy is doing I'm not 100% sure as it's an extern function, so perhaps it's using unmanaged code to block copy?
|
|
|
|
|
|
IMO you're right!
|
|
|
|
|
Use ArrayList.
example:
ArrayList AryObj= new ArrayList();
for (int i=0; i < selec.Item.Count; i++)
{
AryObj.Add(selec.Item[i].Text);
}
|
|
|
|
|
That is bad.
ArrayList is the only list that existed back in .NET 1.0 and 1.1; since 2.0 we have generic lists such as List<int> and there is no real use for ArrayList anymore, it is just an equivalent to List<object> and therefore it is superfluous as a type.
Furthermore it does not contribute at all to the solution of the OP's problem.
|
|
|
|
|
Thanks 
|
|
|
|
|
Dear All,
Would you please advise if there's certain problems in EMGU Library or Accord Library???
I made a program to recognize Sign language using image processing , feature extraction & HMM but I'm not achieving the needed accuracy.
the number of correct recognitions is tooooo much small and I can't apply my project with such errors.
I highly appreciate your help & cooperation.
All the best...
Rima
|
|
|
|
|
Don't just post this everywhere - it duplicates work and can annoy people.
Either post it in QA or post it in the forums - but not both!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
OK & Sorry for this mistake
|
|
|
|
|
RimaTeliani wrote: advise if there's certain problems in EMGU Library or Accord Library?
What problems? If you need help then you need to describe your problem in better detail.
|
|
|
|
|
i don't know actually where is the problem, but I couldn't recognize any video outside the database.
I'm asking if you have faced problems in the HMM from Accord Library or in functions from EMGU library since I don't think that the problem is in the Algorithm.
Many thanks in advance & Best regards,
|
|
|
|
|
RimaTeliani wrote: I made a program to recognize Sign language using image processing , feature extraction & HMM but I'm not achieving the needed accuracy.
the number of correct recognitions is tooooo much small and I can't apply my project with such errors.
You'll need a neural network, and train it on a specific user. Do you "speak" sign? If not, I'd strongly suggest learning baby-sign, roughly a 100 words worth, easy to learn, and gives a wonderful insight in what language is.
My movements are erratic, sometimes closely to spastic. It's hard for a human to determine whether I meant "father" or "mother", if my hand is halfway up my nose. Computers will have the same problem.
That's not much of a problem in the real-world, as there's something like a "context" to a story. If we're talking about women's clothes, you can easily deduce that I meant "mother", not "father".
You've chosen quite a difficult project - but the toughest are often the most rewarding.
Bastard Programmer from Hell
|
|
|
|
|
Dear Eddy,
I highly appreciate your reply.
I have read a lot about sign language and the difficulties of it in different languages but I tried to get over them.
I specified the aim of my project to recognize about 25 words in this initial stage. those words contain movement so my deal is with videos rather than with static images.
as I've noticed, most of the researches in this domain used HMM and got best results than using ANN which is considered as old technique compared to HMM. So, I used HMM and trained it on multiple users.
Can you help me more please.
thanks in advance
|
|
|
|
|
RimaTeliani wrote: I specified the aim of my project to recognize about 25 words in this initial stage. those words contain movement so my deal is with videos rather than with static images.
The hard part therein would be determining when a new word starts, and when it would end. I'd probably select static snapshots at a set interval to analyze, as opposed to a stream.
RimaTeliani wrote: as I've noticed, most of the researches in this domain used HMM and got best results than using ANN which is considered as old technique compared to HMM.
Seems to fit the problem better than a neural network; the Wikipedia shows some links to some more elaborate versions of the algo that are a bit beyond my scope.
RimaTeliani wrote: Can you help me more please.
Not beyond what I already told you.
Bastard Programmer from Hell
|
|
|
|
|
Many thanks Eddy
All the best
|
|
|
|
|
Hi,
I am writing an automated printer driver performance measuring tool. I have one problem that I need to fix.
Please check the sample code below.
What I need to do is, when I add the job to the print queue, I need to "poll" for the "isDeleted" status (or if possible, "isCompleted" status) and display the time (that part is not written in the sample code) it took to finish the job. In this case, "finish" means that the PRN file has been created. (The port of the printer is set to Local port: PRN file path.)
For this, I need to add a pause (of suitably low amount so that it doesn't affect the time) where I have put a comment in the code below.
I can easily do this with a timer, but it got a bit complicated when i kept on adding features. (i would be adding a list of job, would be backing up the PRN files, get time measurement, use two drivers and compare performance etc. etc.)
using System;
using System.Windows.Forms;
using System.Printing;
using System.Threading;
namespace AddJob
{
public partial class frmAddJob : Form
{
public frmAddJob()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Thread printingThread = new Thread(printXPS);
printingThread.SetApartmentState(ApartmentState.STA);
printingThread.Start();
}
private void printXPS()
{
LocalPrintServer lp = new LocalPrintServer();
PrintQueue pq = LocalPrintServer.GetDefaultPrintQueue();
try
{
PrintSystemJobInfo psji = pq.AddJob("myXPSJob", "C:\\test.xps", false);
while (psji.IsDeleted != true)
{
psji.Refresh();
}
MessageBox.Show("Done");
}
catch
{
MessageBox.Show("Error");
}
}
}
}
Does anyone have any tips for me?
|
|
|
|
|
1. you can pause a thread using Thread.Sleep
2. you should not perform blocking operations (such as Thread.Sleep) on the main thread
3. most often a timer is the right way for controlling progress
4. use the timer that fits your needs, there are several types. For simple periodic jobs in a WinForms environment, most often a System.Windows.Forms.Timer is the right one as it ticks on the main thread.
5. always prefer an event-driven approach over a polling approach
6. if you must poll, and a timer-based approach doesn't fit, consider using a BackgroundWorker instead (probably with Thread.Sleep now)
7. for file creation/deletion, the FileSystemWatcher class provides some useful events; warning: they signal the start of an action, not the termination of an action.
8. when "things get complicated while adding features", you probably failed to properly apply an object-oriented approach
9. it isn't adding features that causes complexity, it is brain twisting the wrong way.
|
|
|
|