|
Hi,
I have populated a hashtable called CacheHashTableForwards.
This is how the hashtable gets populated:
CacheHashTablesForwards.Add(IndexName, code)
...
Now I would like to sort this data which is inside the Hashtable.
Not sure if this is a good approach but I use an ArrayList to do this as follows:
CacheHashTablesForwardsArraySorted = new ArrayList(CacheHashTablesForwards.Keys)
As you can see, The sorted array does not contains the other column, i.e. code
How can I properly sort using the arraylist.
Thanks
|
|
|
|
|
Hi,
your ArrayList CacheHashTablesForwardsArraySorted is NOT sorted:
1) the Keys property of a hashtable returns an ICollection containing all the keys, but
MSDN clearly states "The order of the keys in the ICollection is unspecified"
2) giving it a name ending on "Sorted" doesnt do it either.
So you must explicitly sort your ArrayList.
Afterwards, you can enumerate the sorted list, and use the hashtable to look up the
corresponding values.
The alternative is to use a SortedList instead of a HashTable; that one does it all.
|
|
|
|
|
Hello again,
I am now fully using sortedList()
This seems to be what I was looking for.
What is the difference between hashtable and sortedlist apart from the sort please?
|
|
|
|
|
Well, the MSDN documentation is rather abundant on these. Havent studied it in detail.
Seems like SortedList uses just two arrays (and hence needs frequently copying stuff
to insert/remove items), think of it as a normal List that makes sure it remains sorted
at all times, whatever the cost.
HashTable does not care about sorting, it applies a bag of tricks for maximum
performance: it uses a hashing scheme, and linked lists
so it offers best performance especially for large collections or frequent inserts/removals.
|
|
|
|
|
arkiboys wrote: CacheHashTablesForwardsArraySorted = new ArrayList(CacheHashTablesForwards.Keys)
Assuming 'IndexName' implements IComparable, then you can simply add:
CacheHashTablesForwardsArraySorted.Sort();
|
|
|
|
|
I begin learn C#. in C# do not have keyword ReDim Preserve and I wonder how can I change the code below in to C#.
Dim i() as string
Redim i(0)
i(0)= "abc"
ReDim Preserve i(2)
i(1) = "you are the best"
i(2) = "thanks"
|
|
|
|
|
LyBun wrote: C# do not have keyword ReDim Preserve
So, what does it do?
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
Hi,
there basically are two approaches:
1.
use an array; when it needs to grow, create a new one and copy the contents
(e.g. using Array.Copy)
Thats what ReDim does behind the scenes.
2.
use a collection, such as an ArrayList or a List. These act like stretchable arrays,
but are a bit slower in accessing their elements.
So to choose one or the other you must balance the add/remove operations against the
read/write operations.
|
|
|
|
|
Hello Luc,
For strings I like to use the dynamic:
System.Collections.Specialized.StringCollection dynstringarray = new System.Collections.Specialized.StringCollection();
All the best,
Martin
|
|
|
|
|
Hi Martin,
I did not know StringCollection.
I created my own StringList back in the 1.x times, and am still using it...
Thanks for the info.
|
|
|
|
|
Glad I could give you a info!
Doesn't happen so often.
All the best,
Martin
|
|
|
|
|
|
Dear gurus,
I want to make a statistics on the words of any text within a pdf-file.
Do you know how I can access a pdf for my purpose?
thanks in advance
|
|
|
|
|
Hint: try to search CP articles containing the word pdf.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi all,
I am reandering a Data Grid from my web part containing a paging event its giving me post back but grid is rendering twise on the page.
Any suggestion???
<br />
protected override void CreateChildControls()<br />
{<br />
DataTable data = null;<br />
string[] columnArray = null;<br />
bool IsColumns = false;<br />
DataTableValidationStatus tableStatus;<br />
<br />
try<br />
{<br />
if (!String.IsNullOrEmpty(Columns))<br />
{<br />
columnArray = Columns.Replace(" ", "").Split(',');<br />
IsColumns = true;<br />
}<br />
<br />
data = GetDataTable();<br />
tableStatus = Utility.ValidateDataTable(data, true, true, IsColumns, columnArray);<br />
<br />
if (tableStatus == DataTableValidationStatus.Valid)<br />
{<br />
data.Locale = System.Globalization.CultureInfo.InvariantCulture;<br />
<br />
grid.EnableViewState = true;<br />
grid.AutoGenerateColumns = false;<br />
grid.AllowPaging = true;<br />
grid.PageSize = PageSize;<br />
grid.CurrentPageIndex = currentpageindex;<br />
grid.PagerStyle.Mode = PagerMode.NextPrev;<br />
grid.PagerStyle.CssClass = PagerStyleCssClass;<br />
<br />
grid.CssClass = GridCssClass;<br />
grid.AlternatingItemStyle.CssClass = AlternatCssClass;<br />
grid.HeaderStyle.CssClass = HeaderCssClass;<br />
grid.ItemStyle.CssClass = ItemCssClass;<br />
<br />
grid.Width = System.Web.UI.WebControls.Unit.Percentage(100);<br />
<br />
grid.PageIndexChanged += new DataGridPageChangedEventHandler(this.grid_PageIndexChanged);<br />
<br />
grid.DataSource = data;<br />
grid.DataBind();<br />
Controls.Add(grid);<br />
}<br />
}<br />
<br />
private void grid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)<br />
{<br />
currentpageindex = e.NewPageIndex;<br />
BindGrid();<br />
}<br />
Anuj
|
|
|
|
|
Hi All,
I want to use the outlook application in my program i want to use it's option without opening it.
I hear about a line code but i need more help about that.
merwa
|
|
|
|
|
Here's[^] an example on MSDN of how to use MS Outlook in C#.
|
|
|
|
|
in remoting, the choice of the channel for intranet application without firewall protection or allowing communication thru some port, is mostly TCP.we can achieve our functionality by http channel as well.but by using TCP we get performance gain since TCP is faster than HTTP.
Can anyone clarify why communication over TCP channel is Faster than on Http channel
|
|
|
|
|
|
I am try crypt and decrypt the same text. I am use a symetric algorithm (Rijndael), but I don´t understand what happend whit my code. This is the test.
1. I write a text in a textbox (txtSrc).
2. I read the text, crypt it and write it in a label (lblCph1).
3. I read the text in the label and again crypt it y write the result in other label (lblCph2).
In the point 2, I expect the text of the label with strange simbols (cipher it), and in the pint 3 I expect the text of the label in plain text, but it is in strange simbols too. I don´t undertand, I think what if I crypt a text with the same key a pair of time, it will be decrypted. ¿Someone can explain to me?
I have write a example code.
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Security.Cryptography;<br />
using System.IO;<br />
<br />
namespace PruebaSimetrica<br />
{<br />
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
<br />
private void btnCph1_Click(object sender, EventArgs e)<br />
{<br />
byte[] RellenoKey = new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };<br />
byte[] RellenoIV = new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };<br />
Rijndael RijndaelAlg = Rijndael.Create();<br />
RijndaelAlg.Key = RellenoKey;<br />
RijndaelAlg.IV = RellenoIV;<br />
byte[] bytePlainText = Encoding.Default.GetBytes(txtSrc.Text);<br />
byte[] byteCryptText;<br />
<br />
bytePlainText = Encoding.Default.GetBytes(txtSrc.Text);<br />
<br />
MemoryStream mStream = new MemoryStream();<br />
CryptoStream cStream = new CryptoStream(mStream, RijndaelAlg.CreateEncryptor(RijndaelAlg.Key, RijndaelAlg.IV), CryptoStreamMode.Write);<br />
<br />
cStream.Write(bytePlainText, 0, bytePlainText.Length);<br />
cStream.FlushFinalBlock();<br />
<br />
byteCryptText = mStream.ToArray();<br />
<br />
lblcph1.Text = System.Text.Encoding.Default.GetString(byteCryptText);<br />
<br />
cStream.Close();<br />
mStream.Close();<br />
}<br />
<br />
private void btnCph2_Click(object sender, EventArgs e)<br />
{<br />
byte[] RellenoKey = new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };<br />
byte[] RellenoIV = new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };<br />
Rijndael RijndaelAlg = Rijndael.Create();<br />
RijndaelAlg.Key = RellenoKey;<br />
RijndaelAlg.IV = RellenoIV;<br />
byte[] bytePlainText ;<br />
byte[] byteCryptText=Encoding.Default.GetBytes(lblcph1.Text);<br />
<br />
byteCryptText = Encoding.Default.GetBytes(lblcph1.Text);<br />
<br />
MemoryStream mStream = new MemoryStream();<br />
<br />
CryptoStream cStream = new CryptoStream(mStream, RijndaelAlg.CreateEncryptor(RijndaelAlg.Key, RijndaelAlg.IV), CryptoStreamMode.Write);<br />
<br />
cStream.Write(byteCryptText, 0, byteCryptText.Length);<br />
cStream.FlushFinalBlock();<br />
<br />
bytePlainText = mStream.ToArray();<br />
<br />
lblCph2.Text = System.Text.Encoding.Default.GetString(bytePlainText);<br />
<br />
cStream.Close();<br />
mStream.Close();<br />
}<br />
<br />
}<br />
}
Thanks,
Fernando
|
|
|
|
|
To return encrypted text to plain text use CreateDecryptor().
|
|
|
|
|
Yes, it is true, they finally work.
I was a week doing changes.
Thank
Fernando
|
|
|
|
|
Dear All
Regards!
I have a program that opened and read a DXF file format in C# and then draw all the entities in DXF file using openGL, but i can't read the color of these entities which are given in DXF file,
so need program in C# to read the color of each entity i.e circle, polyline,arc etc..,of DXF file and then draw each entitiy i.e circle, polylines etc, in that specific color, as for each entity there is color in DXF file.
kindly help me while writng program for it.
Thanks
David
david
|
|
|
|
|
hey,
i'm writing a hardware lock for my new tailor made software,
my approch is,
For every DML i'll check for the existance of hardware lock,
for this i'll query the hardware to send me some GUID,
comapre this GUID with one from software side,
if it matches then continue else stop
(the hardware for this will be designed according requirments given)
now questions :->
Should i use serial port or usb ? (in terms of processing time)
use a function to generate this GUID ?(well i will surely do tht, but whts the general practice/ algorithm)
will this ID be machine dependent?
becoz what i want is one installation CD with one hardware lock which can work on any machine?
give me an idea, as i'm thinking tht it wont be as simple as wht i'm thinking
regards,
logicaldna
|
|
|
|
|
I will answer the hardware part only:
it has to be USB, since a modern PC (desktop or laptop) has 2, 4, 6 or more USB ports
and often 0 serial ports.
furthermore, if I need several hardware locks, its much easier to add USB ports (using
a USB hub), than it is to add serial ports.
and lastly you can easily have USB ports at a distance, such as the USB ports found on
many desktop monitors.
The performance issue AFAIK is irrelevant since an app will typically check the hardware
lock only once (at startup), or a couple of times (when saving something),
certainly not all the time.
BTW there are companies such as WIBU[^] that sell
USB hardware locks; they are organized in such a way
that they can hold a number of keys plus a couple KB of app data; so a new software
can be linked to either an existing key or a new, empty key, and that is how it should be.
And of course, companies that offer hardware keys also have the necessary software
to support them, including an API to integrate it in the app itself.
To sum it up, whatever your software product is going to be, if it comes with a
serial port hardware lock I wont buy it. If it works with a USB key, it better be
from a trusted hardware source and able to combine with other protected packages...
So I dont see the point in reinventing stuff that exists and performs well.
|
|
|
|
|