|
|
hi,
Why there is a split between IEnumerator and IEnumerable. I mean, why did the designers of .NET decide it was necessary to implement 2 interfaces in order to support enumeration?
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
You have to implement every methods of any interface you implement... (stupid sentence, i know)
So, if you just need to be "enumberable", you can simply implement that interface.
Cheers
Sebastian
|
|
|
|
|
hi,
My question is Why Framework Designers kept two interface for achiving one idea. That is cusom Enumeration through a custum collection.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
sreejith ss nair wrote:
why did the designers of .NET decide it was necessary to implement 2 interfaces in order to support enumeration?
Because you might want to have two separate threads enumerate over the same collection at the same time. Because the iteration model used in .NET does not permit alterations to a collection during enumeration this is completely safe.
The IEnumerator interface allows you to get the current state of a particular enumeration. While the IEnumerable interface allows you to retrieve a (normally new) IEnumerator object.
So, if you have two threads they can both get separate objects with an IEnumerator interface to the same collection - and both threads can iterate over the collection at their own speed without coliding with one another.
Also, it allows you to provide sevaral different ways to enumerate over one collection. A collection, through the IEnumerable interface, can expose a default enumeration, while it can also expose more object with the IEnumerator interface for other non-default enumerations. For instance, the default enumerator could just iterate through the collection in the order in which the data appears. While a second IEnumerator could expose the contents of the collection in a particular sort order, or with some filter.
Does this help?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
hi,
Thanks for this information. Yesterday i wrote an article discussing IEnumerable, IEnumerator. And i got a suggection which ask "why microsoft desided like that ?". I can't able to help him out. Now i can and i will do it.
Url. http://www.codeproject.com/csharp/sssienumerable.asp
thanks
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
See also my artice on the same subject: http://www.codeproject.com/csharp/csenumerators.asp[^]
Although I have to admit that I didn't really think about it all that much until you mentioned it here - Maybe it is time to update my article too.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
So then the question changes to why didn't they call them "IThreadSafeEnumerator" and "IAmNotAThreadSafeEnumerator" or something more self-explanatory like that.
Matt Gerrans
|
|
|
|
|
Matt Gerrans wrote:
So then the question changes to why didn't they call them "IThreadSafeEnumerator" and "IAmNotAThreadSafeEnumerator" or something more self-explanatory like that.
Because the thread safety issue is just one example (I should have said that more clearly). Another example is nesting two iterations inside each other that are iterating over the same collection, you wouldn't want the inner loop to corrupt the state of the outer loop.
Does this clear this up a bit better?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
Sure, but what I meant was that IEnumerable vs. IEnumerator conveys no difference to the reader; it sounds like two different names for the same thing.
Of course the presence of these two interfaces that are apparently the same thing will cause the conscientious programmer to learn what the differences are, but the lack of distinction in the terminology will always make it more difficult to remember which was which.
So perhaps Enumerator and SafeEnumerator would do the trick (I really don't see the point of cluttering up all interfaces with the 'I' prefix either -- if you don't know it is an interface, you'll find out soon as you try using the new operator on it).
|
|
|
|
|
Anonymous wrote:
IEnumerable vs. IEnumerator conveys no difference to the reader
Anonymous wrote:
but the lack of distinction in the terminology will always make it more difficult to remember which was which.
Yes, it does convey a difference. Words ending in -able convey the meaning that of ability to do something (In this case a collection has the ability to enumerate) and words ending in -or are agent nouns, they convey the meaning of the someone or something that does something.
The collection is enumerable - because you have the ability to iterate over its elements.
The Enumerator is the thing that actually does the iteration.
Anonymous wrote:
I really don't see the point of cluttering up all interfaces with the 'I' prefix either
Historical reasons I suppose - the last vestiges of hungarian notation creeping into .NET
Anonymous wrote:
if you don't know it is an interface, you'll find out soon as you try using the new operator on it
Wouldn't it be quicker not to waste time on that?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
Hi all,
I'm looking to implement a web-style UI using Windows Forms and C#. I want my task screens' content to fill the width of the window and to reflow nicely, like a web browser.
While I realise the docking features of Windows Forms are great for resizing content to fit a window, you run into problems when, say, the word-wrapping in a static text control changes such that the line count changes (2 lines become 3, for example). In such a situation, you'd want the controls below the static to shuffle up or down accordingly, but the docking properties aren't enough to cater for this.
Has anyone seen any Forms code that avoids ugly spaces opening up (or conversely, overlapping controls) by correctly reflowing the form's content?
Cheers,
Mal.
|
|
|
|
|
hi,
put little R and D on Anchoring and docking. It may help you out.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Thanks for the reply, but as I explained, the anchoring and docking aren't enough.
Unless, that is, you're telling me to handle the Layout event and do my own layout control? But that's the example I'm hoping I can find without having to code it myself.
Cheers,
Mal.
|
|
|
|
|
Although I don't know of any flow-layout panel code you could use it shouldn't be too hard to do it yourself.
Derive from Panel and override the Resize event handler to calculate the size your child controls will need and then adjust their position accordingly.
Regards,
mav
|
|
|
|
|
 ReHi!
Because such a flow panel could be useful for me too, I wrote a quick initial version.
You can try it out if you like:
public class FlowLayoutPanel : Panel
{
public FlowLayoutPanel()
{}
private Orientation _orient = Orientation.Horizontal;
[DefaultValue(Orientation.Horizontal)]
public Orientation Orientation
{
get { return _orient; }
set
{
_orient = value;
RecalcLayout();
Invalidate();
}
}
private void RecalcLayout()
{
if (this.Controls.Count==0)
{
this.Size = new System.Drawing.Size(100,100);
return;
}
int x=0,y=0,h=0,w=0;
if (Orientation == Orientation.Horizontal)
{
foreach (Control c in Controls)
{
if (x+c.Width > this.Width)
{
x = 0;
y = h+1;
}
c.Left = x;
c.Top = y;
h = Math.Max(h,c.Bottom);
x += c.Width;
}
this.Height = h;
}
else
{
foreach (Control c in Controls)
{
if (y+c.Height > this.Height)
{
y = 0;
x = w+1;
}
c.Left = x;
c.Top = y;
w = Math.Max(w,c.Right);
y += c.Height;
}
this.Width = w;
}
}
protected override void OnResize(EventArgs eventargs)
{
RecalcLayout();
base.OnResize (eventargs);
}
protected override void OnControlAdded(ControlEventArgs e)
{
RecalcLayout();
base.OnControlAdded (e);
}
protected override void OnControlRemoved(ControlEventArgs e)
{
RecalcLayout();
base.OnControlRemoved (e);
}
}
Regards,
mav
|
|
|
|
|
Thanks - will check it out pronto.
Mal.
|
|
|
|
|
Hi!
Does anyone know, how i can call javascript functions in a web document from a winform application. like the article JavaScript call from C++
|
|
|
|
|
how do i disable the close button on the top right corner of a window form?
chris
|
|
|
|
|
Hi Cris,
It involves P/Invoking
1.GetSystemMenu
2.GetMenuItemCount
3.RemoveMenu
4.DrawMenuBar
API methods declaration and DisableCloseButton function can be written as below:
[DllImport("user32.Dll")]
public static extern IntPtr RemoveMenu(int hMenu, int nPosition,long wFlags);
[DllImport("User32.Dll")]
public static extern IntPtr GetSystemMenu(int hWnd, bool bRevert);
[DllImport("User32.Dll")]
public static extern IntPtr GetMenuItemCount(int hMenu);
[DllImport("User32.Dll")]
public static extern IntPtr DrawMenuBar(int hwnd);
private const int MF_BYPOSITION = 0x400;
private const int MF_REMOVE = 0x1000;
private const int MF_DISABLED = 0x2;
public void DisableCloseButton(int hWnd)
{
IntPtr hMenu;
IntPtr menuItemCount;
hMenu = GetSystemMenu(hWnd, false);
menuItemCount = GetMenuItemCount(hMenu.ToInt32());
RemoveMenu(hMenu.ToInt32(), menuItemCount.ToInt32() - 1,MF_DISABLED | MF_BYPOSITION);
RemoveMenu(hMenu.ToInt32(), menuItemCount.ToInt32() - 2,MF_DISABLED | MF_BYPOSITION);
DrawMenuBar(hWnd);
}
Do revert back whether it could do the desired thing or not.
Please Note that User can also close the application using Alt+F4. you should handle that aspect as well, which can be done very easily by overriding wndProc method.
Regards,
Jay
|
|
|
|
|
If you don't need the Minimize, Maximize and Help Button simply set the Form.ControlBox property false.
www.troschuetz.de
|
|
|
|
|
HI,
i got the Tlbimp.exe at path
C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Bin\Tlbimp.exe
I have my Atl(COM) DLL at f:\ComDll.dll
this dll is written by me in VC++ (ATL COM wizard) it has some functions i want to use these functions in my ASP.Net net web page.
How can i Import it or use it in ASP.Net using C#.
Plz reply me urgent
at zahid_ash@hotmail.com
or
zahid_ash@yahoo.com
thanx
Regards.
|
|
|
|
|
hi,
You can easily bind com components using vs.net sdk. Go to reference folder of your project and right click to get the Add reference option. Choose that option and choose com tab. Then you can browse and locate the directry which contain your dll.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
i did that all is fine upto this.
But now in ASP.Net i Add a Button under this button Event i want to use the Function of that DLL.
say function is Test(.. ,..),, and Class is MyClass in COM DLL.
How can i use it in C# , Means how can i create the Object of that class to call the Function.
the name shown is refernce folder after adding refernce is COMDLLLib , and name is Interop.COMDLLLib.
what thew way to create object and call function
thanx
Regards.
|
|
|
|
|
hi,
Refer your dll on namespace reference location.
Like
using system;
using yourdll;
etc.
then
try to create instance on your event handler location.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|