|
Christian Graus wrote: foreach is just a for loop, the compiler inserts the for loop in place of your code
You are wrong here. foreach only works on IEnumerable and is using an IEnumerator internally.
Robert
|
|
|
|
|
Really ? OK. I knew it was just syntactic sugar, but apparently I got the details wrong. Thanks for the heads up.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
For You :
For Loop is the best option
Develop2Program & Program2Develop
|
|
|
|
|
How on earth could you possibly say that without knowing anything about the situation it's going to be used in or what the requirements are?
|
|
|
|
|
the assumption that the OP is a clueless noob because he posted without answering any of your questions.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
|
The best iterator is the one that gives the most readable code in the context it is used in.
|
|
|
|
|
Nice answer.
|
|
|
|
|
There is no best iterator.
That's why there is more than one, it all depends on the circumstances
(or your definition of best: performance, readability, susceptibility to
mistakes, ...).
|
|
|
|
|
They are all about the same when using smaller data sets. The only time you will notice differences in speed between the iterators is when you use large data sets. By large data sets I mean in the 100,000 plus data records range. But there are other factors involved here as well such as the operations being done between the iterations.
For best optimization look at the operations being done between the iterations and I'm guessing you will gain more speed over changing your iterator.
Phil
|
|
|
|
|
|
How can I detect whether a certain field retrieved from the database contains an image or other type of blob?
I have a MSAccess table with an OLE-Object field holding a bitmap. This field is added to the DataTable as an System.Byte[] type. How do I know whether this field actually holds an bitmap?
Thanks for any help you can give.
Regards,
Kees Vermeulen
|
|
|
|
|
The only way you can get this info is by inspecting the data in the field. You can either extract it and try to load it into an image or you can read the header bytes to see if they conform to known types.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
|
I am using .NET 3.9 in VS 2005. If I double-click on control to create a click event, nothing happens. There is also no event tab in the properties window.
Does anyone have an idea on what could cause this / what the cure is ?
Johan Lombaard
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former - Albert Einstein
|
|
|
|
|
Oops, .NET 3.0
Johan Lombaard
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former - Albert Einstein
|
|
|
|
|
You need to define the event with the associated event handler in XAML markup. VS 2005 (with WPF) wont automatically create an default event handler when you double click a control.
|
|
|
|
|
I have .NET 3.0 installed. I've not noticed any side-effects.
Kevin
|
|
|
|
|
I have an class library which uses Micrisoft Office Excel Object library for creating Excel objects. I want to include these dll's as a part of my class library dll. I tried using ILMerge utility, but could not merge these assemblies. Since Micrisoft.Office.Interop.Excel is a COM object I tried converting it into .Net assembly by using tlbImp. But am not able to do it. Please help in including it with my dll.
|
|
|
|
|
You can't. The client has to have Office installed in order to use this.
tlbImp doesn't convert anything to a .NET assembly. It creates a Runtime Callable Wrapper assembly that has to be used ALONG WITH the COM component. It will NOT replace the COM component.
|
|
|
|
|
Thanks a lot for the reply. I can understand that the client needs to have Excel installed on its machine. But I wish to use my library as a component so that the client may just add a reference to my dll and then call the required functions. For this to happen in current scenario the client will have to have the excel object library too in the bin folder.
|
|
|
|
|
jain.ashish21 wrote: For this to happen in current scenario the client will have to have the excel object library too in the bin folder.
Is that such a big deal?
|
|
|
|
|
Dear sirs:
I wrote program that performs one resource-intensive operation. This operation is to convert PDF into a text file. I decided to spin-off this single operation on a threading delegate as shown below:
Class Pdf()
{
public delegate string PdfIsbn();
string ISearch.Isbn( string sFileName )
{
m_sFileName = sFileName;
PdfIsbn pdfIsbn = new PdfIsbn( GetIsbn );
IAsyncResult iasResult = pdfIsbn.BeginInvoke( new AsyncCallback( IsbnComplete ) , "Isbn is complete" );
/**********************************
******** Regular Processing *******
**********************************/
// It only works if this code is un-commented.
while (!iasResult.IsCompleted)
{
Console.WriteLine("Please wait...");
//return m_sIsbn;
}
return m_sIsbn;
}
private void IsbnComplete( IAsyncResult iasResult )
{
AsyncResult ar = ( AsyncResult )iasResult;
PdfIsbn pdfIsbn = ( PdfIsbn )ar.AsyncDelegate;
m_sIsbn = pdfIsbn.EndInvoke( iasResult );
Constant.g_iThreadCount -= 1;
}
string GetIsbn()
{
Constant.g_iThreadCount += 1; // Increment thread-counter.
Console.WriteLine( "Pdf version of search implemented" );
Thread.Sleep(5000);
dtSearch dtSrch = new dtSearch( m_sFileName ); // Pass-in filename only.
regEx = new RegEx( "Isbn" ); // Search for a regular expression that fits the "ISBN"-type.
SearchIsbn( regEx , dtSrch.ResultText );
return m_sIsbn = regEx.RegExResult; // Get the ISBN.
}
}
The Main program is a windows form with a DataGridView. The main loop cycles through subfolders; each one containing a PDF.
do
{
try
{
file.GetDirectory(); // gets a book inside a directory, performs search etc.
// If a valid ISBN is found it will show up here.
if (file.SearchItem != "")
{
newBooks.AddBook(new Book(true, file.FileName, file.SearchItem));
}
}
catch (Exception ex)
{
file.LogError(ex, ex.Message.ToString());
}
} while ( file.SubFolder != "sub-folder iteration completed." ) ;
bindingSourceEbookCollection.DataSource = newBooks;
dataGridViewEbookCollection.DataSource = bindingSourceEbookCollection;
dataGridViewEbookCollection.AutoGenerateColumns = true;
I have tried to make the grid "aware" of all of the new book-entries being made inside the collection to which it is bound; to no avail.
I tried using a global "Thread Counter" so that the loop would keep executing until all the threads have been processed; and putting the "grid-binding" code inside the loop with the intent being that it would be "refreshed" with the new book-data.
The way the code is written now, the books show up but only after they have ALL been processed and the grid is blank until the whole process (all books) is completed.
The idea behind "encapsulating" the single, resource-intensive process inside a thread was to show the status of "processing... " inside the data grid for each book that was spun-off on a thread.
Any help is appreciated.
Many thanks,
R. Hyland
|
|
|
|
|
Maybe I am missing something here, but it seems like you should be updating your grid when the async event comes back:
private void IsbnComplete( IAsyncResult iasResult )
{
Then you need to do something like Application.DoEvents for your grid to repaint.
Hope that helps.
Ben
|
|
|
|
|
Thanks, I finally got it to work per your advice.
-- modified at 15:19 Thursday 24th May, 2007
|
|
|
|