|
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
|
|
|
|
|
I was having trouble with the string.Split() method. I thought It returned a character array .. but I could be wrong.
I ended up using Regex.Split() to accomplish this.
Thanks for the help.
|
|
|
|
|
you can use Split like this...
C#:
<br><br><font color="blue">private</font> <font color="blue">void</font> button1_Click(<font color="blue">object</font> sender, System.EventArgs e)
<br>{
<br><font color="darkgreen"> <font color="blue">string</font></font>[] str="Here is my string".Split(' ');<font color="darkgreen">
<br> <font color="blue">for</font></font>(<font color="darkgreen"><font color="blue">int</font> </font>x=str.GetLowerBound(0);x!=str.GetUpperBound(0)+1;x++)<font color="darkgreen">
<br></font> {
<br> MessageBox.Show(str[x]);
<br> }
<br>}
<br>
|
|
|
|
|
mikemilano wrote:
I was having trouble with the string.Split() method. I thought It returned a character array .. but I could be wrong.
Well, it takes a character array containing delimiter characters as an input parameter and returns a String array, this means that the example from my previous post would return an array containing 6 items, i.e.
strArray[0] - "Here"
strArray[1] - "is"
strArray[2] - "my"
strArray[3] - "string"
strArray[4] - "hello"
strArray[5] - "world!"
(as we have specified space and comma as delimiter characters.)
Rado
|
|
|
|
|
thank you , .. this really clears things up a lot.
i was trying to send it a string.. and not a character array.
i really do appreciate all the help!
|
|
|
|
|
Hi,
I have built a simple applicaton that accesses an XML file located on a remote web server using the XmlTextReader class. The application works flawlessly on all my machines, but throws the following exception when ran on my friend's PC (this is the Message property of the Exception):
Request for the permission of type System.Net.WebPermission, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
I've been looking for differences between our machines and I've found that when I run the Microsoft .NET Framework 1.1 Configuration from Administrative Tools, and select the "Evaluate Assembly" from the "Runtime Security Policy" node, on my machine the list contains only one item - Unrestricted, whilst on my friends machine it contains a longer list which does not contain "Web access" permission. I guess that this is the reason of the application's inability to access the resource (the remote XML file). I guess his OS is Windows XP, I am using Windows 2000.
And here I am stuck. I didn't find a way how to configure application/assembly permissions using the .NET Framework Configuration on my machine (I was trying to remove the "Web access" permission for this application on my PC) and also I don't know how to add the "Web access" permission on my friend's PC.
Does anyone have a clue how this can be achieved? Thanks a lot in advance.
Rado
|
|
|
|
|
Well, howto particularly approve this permission I am not aware of. But go to administration tools/.Net Wizards/Adjust .Net security, and you will be able to change your permissions settings.
Gooky
|
|
|
|
|
I want to connect dataset table (returning dataset form a web services) with a table in a datagrid. The problem is I just want to use a selected amount of columns from the dataset.
Any ideas would be appreciated
Thanks
|
|
|
|
|
Are you autogenerating the columns in the datagrid?
Just so I understand. You are populating the datagrid with one dataset and want to add another dataset (from a webservice)?
Have you look at the merge method?
|
|
|
|
|
You need to create your to add a table styles object to the tablestyles collection. This will allow you to specify column mappings and so on. Of course you could set the width to 0 and that would also hide them
This way is better in that you can create custom columns like check bools combos and what not
example:
DataGridTableStyle newStyle = new DataGridTableStyle();
newStyle.MappingName = "CCheckInList"; // This is the name of the table
newStyle.ColumnHeadersVisible = true;
DataGridTextBoxColumn gridColumn = new DataGridTextBoxColumn();
gridColumn.MappingName = "Dispatcher"; // This is the column name
gridColumn.NullText = "Must Assign";
gridColumn.HeaderText = "Dispatcher";
gridColumn.Width = 100;
newStyle.GridColumnStyles.Add(gridColumn);
TableStyles.Clear();
this.TableStyles.Add(newStyle);
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|