|
Hi, just want to know how to separate method declaration and implementation.
Example:
namespace anothersucker
{
public class SomeClass : IA, IB, IC
{
//QUESTION: How can I do implementation elsewhere so I can separate declaration and implementation like we do in C++
public void DoA() {return;}
protected void DoB() {return;}
public void DoC() {return;}
public void DoD() {return;}
}
}
norm
|
|
|
|
|
|
|
|
no, .NET is not lame at all, big step forward from the lame MFC. i was just bitching that you can't separate declaration and implementation in C#.
.net framework is so much more intuitive and organized and with much shorter learnign curve than MFC/WIN32. documentation is much better.. just so much better.
norm
|
|
|
|
|
I'll agree with that. I'll be most happy if/when they finally make C# be a language that keeps up with modern concepts (which it does now), does not have the excess baggage/clutter of C++ (C# is good here), AND has the power that C++ achieves (they have a ways to go here). It's definitely not too hard to accomplish.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
despite all .net languages compile to MSIL, i thought managed C++ has more optimized IL than others?
norm
|
|
|
|
|
No, it doesn't. But you can mix managed and unmanaged code in Managed C++.
BTW, what makes managed code slower than unmanaged code is that it has to be compiled at runtime.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
jdunlap wrote:
what makes managed code slower than unmanaged code is that it has to be compiled at runtime
Don't forget about all of the code optimizations your regular C/C++ compilers will make. While it is possible for the JIT compiler to do this in the future, I don't think it can optimize as much as the unmanaged C++ compiler, yet.
James
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
One way to approximate that is use delegates.
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
is there any way to remove duplicates in an array or an arraylist? i see there are no functions, but i'm having a hard time wrapping my head around making an function which will do this.
|
|
|
|
|
Why don't u try using another class like Hashtable or DictionaryEntry struct..
they take a key-value pair..and do not allow duplicate keys..
also the read/access time of these is O(1)
|
|
|
|
|
Krishnan11111977 wrote:
also the read/access time of these is O(1)
Thats not quite correct, it is realistically close to O(1) but under bad circumstances it can be O(n).
Unfortunately, I've seen examples where people override GetHashCode and have it return a constant value. This would be one of those 'bad circumstances' because the Hashtable would have to search through all of the keys that returned the same hash code (ie all of them) to find the correct key.
Usually this is done when someone doesn't know how they should override GetHashCode when they override Equals . The contract is that if two objects are considered equal then the hash code must be the same. Another part of the contract is that an object must return the same hash code over its lifetime. Because of those two details, it can be tricky for someone to correctly override GetHashCode while also overriding Equals .
I didn't intend to write this much, honest!
[edit]I do agree, using a Hashtable should be a quick way of determining if you have a duplicate item.[/edit]
James
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
I've designed a class (not a control) that has some custom events. Then I want to clear the class of it's current values, refill the values, and then re-register to the events, as different clients listen to different events. But how do I clear the event queue (or whatever the += syntax adds events to) of the previous events? I haven't seen any good examples of -= syntax nor can I find any in the MSDN docs.
Any ideas?
|
|
|
|
|
The following seems to work:
myClass.MyEvent = null;
Don't you love it when you answer your own questions?
|
|
|
|
|
Here's how I do it in VC6:
- Load a dialog resource in the resource editor
- Add an edit box
- Open the Properties box
- Click on the Extended Styles tab
- Click on the Modal Frame checkbox
How is this done for C# using SharpDevelop or VS.NET?
I wouldn't mind doing it programmatically. I just couldn't find an ExtendedStyles property for the textbox control.
Thanks in advance!
Alvaro
If you want to get to the top, prepare to kiss a lot of bottom. -- despair.com
|
|
|
|
|
override the CreateParams property, and hardcode the implementation for "get".
FYI, the default implementation is :
protected override CreateParams get_CreateParams()
{
CreateParams params1;
IWin32Window window1;
Form form1;
Form form2;
params1 = base.CreateParams;
if (this.TopLevel)
{
params1.Style = (params1.Style & -134217729);
}
if (this.TopLevel && (this.formState[Form.FormStateAllowLayered] != null))
{
params1.ExStyle = (params1.ExStyle | 524288);
}
window1 = ((IWin32Window) base.Properties.GetObject(Form.PropDialogOwner));
if (window1 != null)
{
params1.Parent = window1.Handle;
}
this.FillInCreateParamsBorderStyles(params1);
this.FillInCreateParamsWindowState(params1);
this.FillInCreateParamsBorderIcons(params1);
if (this.formState[Form.FormStateTaskBar] != null)
{
params1.ExStyle = (params1.ExStyle | 262144);
}
if (this.IsMdiChild)
{
if (base.Visible && ((this.WindowState == 2) || (this.WindowState == 0)))
{
form1 = ((Form) base.Properties.GetObject(Form.PropFormMdiParent));
form2 = form1.ActiveMdiChild;
if ((form2 != null) && (form2.WindowState == 2))
{
params1.Style = (params1.Style | 16777216);
this.formState[Form.FormStateWindowState] = 2;
base.SetState(65536, 1);
}
}
if (this.formState[Form.FormStateMdiChildMax] != null)
{
params1.Style = (params1.Style | 16777216);
}
params1.ExStyle = (params1.ExStyle | 64);
}
if (this.TopLevel || this.IsMdiChild)
{
this.FillInCreateParamsStartPosition(params1);
if ((params1.Style & 268435456) != 0)
{
this.formState[Form.FormStateShowWindowOnCreate] = 1;
params1.Style = (params1.Style & -268435457);
}
}
if (this.IsRestrictedWindow)
{
params1.Caption = this.RestrictedWindowText(params1.Caption);
}
return params1;
}
Reflector is your friend!
RSS feed
|
|
|
|
|
Yes, just to change window style (1 check in VC IDE) you now have no choice but to wrap somebodies control and overload the method.
Great!...
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
In its current .NET 1.x implementation, winforms is crap. I hope that .NET 2.0 brings a brand new stuff to play with.
RSS feed
|
|
|
|
|
I hope that .NET 2.0 brings a brand new stuff to play with.
I doubt. But we will see.
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
How can I read the pre-existing attributes that are found in the AssemblyInfo.cs file?
|
|
|
|
|
I use the following methods to fill the About Box. There may be better ways to do it, as this was some of the first .NET code I wrote, but it works.
public string GetCopyright( Assembly a )
{
Type tCopyRight = Type.GetType( "System.Reflection.AssemblyCopyrightAttribute" );
Object[] ao = a.GetCustomAttributes( tCopyRight, false );
if( ao != null && ao.Length == 1 )
{
AssemblyCopyrightAttribute attribute = ao[0] as AssemblyCopyrightAttribute;
if( attribute != null )
return attribute.Copyright;
}
}
public string GetProduct( Assembly a )
{
Type tProduct = Type.GetType( "System.Reflection.AssemblyProductAttribute" );
Object[] ao = a.GetCustomAttributes( tProduct, false );
if( ao != null && ao.Length == 1 )
{
AssemblyProductAttribute attribute = ao[0] as AssemblyProductAttribute;
if( attribute != null )
return attribute.Product;
}
}
public string GetTitle( Assembly a )
{
Type tTitle = Type.GetType( "System.Reflection.AssemblyTitleAttribute" );
Object[] ao = a.GetCustomAttributes( tTitle, false );
if( ao != null && ao.Length == 1 )
{
AssemblyTitleAttribute attribute = ao[0] as AssemblyTitleAttribute;
if( attribute != null )
return attribute.Title;
}
}
public string GetVersion( Assembly a )
{
return a.GetName().Version.ToString();
}
|
|
|
|
|
Thanks for the reply. I tried something similiar to what you have posted, but nothing is returned for the title. Even thought I have an entry in the Assembly title attribute AssemblyInfo.cs file. Any idea why this might happen ?
|
|
|
|
|
i would like to explode a string into an array, .. but not each character into an array.
in php the code would be:
<br />
$string = "Here is my string";<br />
$array = explode(" ",$string);<br />
$array[0] would be "Here"
$array[1] would be "is"
i need to explode a string in c#, but with a more complicated explode parameter. is there any functions i'm missing here that would do this?
|
|
|
|
|
I think that the String.Split method is what you're looking for. You can even use several distinct delimiter characters:
<br />
string strSource="Here is my string, hello world!";<br />
string[] strArray=strSource.Split(new Char[] {' ', ','});<br />
foreach(string str in strArray) Console.WriteLine(str);<br />
Hope this helps!
Rado
|
|
|
|