|
egpuyos wrote: Dictionary myDictionary = new Dictionary();
Does this even compiles?
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
sorry it was
Dictionary<byte[], string> myDictionary = new Dictionary<byte[], string>();
|
|
|
|
|
What do you think the output of:
string test = "test";
byte[] b1 = Encoding.Default.GetBytes(test);
byte[] b2 = Encoding.Default.GetBytes(test);
Console.WriteLine(b1 == b2); It will be false as arrays are reference type and compared with reference equality. This is the reason why your code fails. BTW, what is wrong in keeping the string itself rather than the bytes?
|
|
|
|
|
Actually Sir, it was just my sample code, the real code I have is this.
I don't understand why that the dictionary when I call the method Exists, it will return false while it already contain the key that I passed? How could it happen?
Thank you again with you're help Sir.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
private static Dictionary<byte[], string> m_MyDictionary = null;
private static System.Text.ASCIIEncoding m_MyEncoding = new ASCIIEncoding();
static void Main(string[] args)
{
m_MyDictionary = new Dictionary<byte[], string>();
AddDataToDictionary();
Console.Write(Exists(m_MyEncoding.GetBytes("test 003")));
Console.Read();
}
private static void AddDataToDictionary()
{
string s;
byte[] myByte;
s = "test 001";
myByte = m_MyEncoding.GetBytes(s);
m_MyDictionary.Add(myByte, s);
s = "test 002";
myByte = m_MyEncoding.GetBytes(s);
m_MyDictionary.Add(myByte, s);
s = "test 003";
myByte = m_MyEncoding.GetBytes(s);
m_MyDictionary.Add(myByte, s);
s = "test 004";
myByte = m_MyEncoding.GetBytes(s);
m_MyDictionary.Add(myByte, s);
s = "test 0021537912";
myByte = m_MyEncoding.GetBytes(s);
m_MyDictionary.Add(myByte, s);
s = "test 327487";
myByte = m_MyEncoding.GetBytes(s);
m_MyDictionary.Add(myByte, s);
}
private static bool Exists(byte[] key)
{
return m_MyDictionary.ContainsKey(key);
}
}
}
|
|
|
|
|
Dictionary.ContainsKey checks for value on value types, for reference on ref types.
As N a v a n e e t h said, two arrays with identical type, size and content are considered different, they are two distinct objects with different references.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
This is the whole code Sir, thank you with the help
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Dictionary<byte[], string> myDictionary = new Dictionary<byte[], string>();
System.Text.ASCIIEncoding myEncoding = new ASCIIEncoding();
string s;
byte[] myByte;
s = "test 001";
myByte = myEncoding.GetBytes(s);
myDictionary.Add(myByte, s);
s = "test 002";
myByte = myEncoding.GetBytes(s);
myDictionary.Add(myByte, s);
s = "test 003";
myByte = myEncoding.GetBytes(s);
myDictionary.Add(myByte, s);
s = "test 004";
myByte = myEncoding.GetBytes(s);
myDictionary.Add(myByte, s);
s = "test 0021537912";
myByte = myEncoding.GetBytes(s);
myDictionary.Add(myByte, s);
s = "test 327487";
myByte = myEncoding.GetBytes(s);
myDictionary.Add(myByte, s);
string theString = "test 004";
byte[] find = myEncoding.GetBytes(theString);
if (myDictionary.ContainsKey(find))
{
Console.Write(find);
}
else
{
Console.Write("key not found.");
}
Console.Read();
}
}
}
|
|
|
|
|
hi,
you use the byte array as key instead of the string you are adding as value ?!?
why you don't add the string as key and the byte array as value. in your code above i see that would make no difference to the functionality and i think that would be the better way.
greetz
|
|
|
|
|
hey all,
i want to create a window service which send mail automatically at a given interval or any other condition.service should start with system boot n stop with system shutdown . i am not familiar with window services. thanks in advance for ur help n rplies.
|
|
|
|
|
Hi,
have a look here:
Simple Windows Service Sample[^]
It is a little bit old (e.g. using VS 2003), but the idea behind the article is still actual.
Regards
Sebastian
|
|
|
|
|
thanks Sebastian
actually i want to create a service which sends mails at the interval of 15 days. thanks for ur response
|
|
|
|
|
Hi,
How to get the menu like Cut,Copy,Paste,SelectAll in richTextBox.
Any idea?
Thanks,
Subbu
|
|
|
|
|
Combine the RichTextBox with a ContextMenu control, and do the methods of Cut, Copy, etc. in ContextMenu control?
|
|
|
|
|
Thanks for your prompt reply.
Here my question suppose If I am having two RichTextBox and Shall I want to create two ContextMenu Control or I can use One and refer two Rich textbox. Please explain.
|
|
|
|
|
As d@nish said below, that is 100% possible. You just have to set the ContextMenuStrip Property for those two of your RichTextBoxes, enjoying the coding time.
|
|
|
|
|
There is a ContextMenu property for a RichTextBox. You can use that to add a context menu with whatever items you like.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
I used SMO to manage SQL server 2005.
I want to modify a column to be same with other column.
I used the following code but it has error while calling Column.Alter() function.
<code>
public void RepairColumns(object dcolumn)
{
try
{
Column d_Column = (Column)dcolumn;
Column l_Column = mServer.Databases[mSMOInfo.DBName].Tables[mSMOInfo.TableIndex].Columns[mSMOInfo.ColumnIndex];
l_Column.Initialize(true);
l_Column.Collation = d_Column.Collation;
l_Column.Computed = d_Column.Computed;
l_Column.ComputedText = d_Column.ComputedText;
l_Column.DataType = d_Column.DataType;
l_Column.Default = d_Column.Default;
l_Column.Identity = d_Column.Identity; string str = d_Column.Properties[1].Name;
l_Column.IdentityIncrement = d_Column.IdentityIncrement;
l_Column.IdentitySeed = d_Column.IdentitySeed;
l_Column.NotForReplication = d_Column.NotForReplication;
l_Column.Nullable = d_Column.Nullable;
l_Column.RowGuidCol = d_Column.RowGuidCol;
l_Column.Rule = d_Column.Rule;
l_Column.RuleSchema = d_Column.RuleSchema;
l_Column.IsPersisted = d_Column.IsPersisted;
l_Column.DefaultSchema = d_Column.DefaultSchema;
l_Column.Alter();
}
catch (SmoException ex)
{
throw ex;
}
}
</code>
If u knows my mistakes, pls point me.
Thanks
|
|
|
|
|
Hi,
could you post the error message? This would help us to understand the problem a bit better.
Regards
Sebastian
|
|
|
|
|
I use adventurework database.
Error is
FailedOperationException - "Alter failed for Column 'SystemInformationID'."
InnerExcetpion - "Modifying the Computed property of the Column object is not allowed. You must drop and recreate the object with the desired property."
|
|
|
|
|
Setting the computed property does only work if you drop and add the column. (As the error message is saying):
http://www.windows-tech.info/15/83beeb9f84f9b78a.php[^]
Do you need to change the computed value of the column? If not, just leave the line
l_Column.Computed = d_Column.Computed;
out.
|
|
|
|
|
Thank for ur reply.
My goal is to change the column properties to be the same with other column.
I already left "Computed" property but an error has been occur with the other property of the column.
|
|
|
|
|
Well... Do you change any default settings of your database server... Can you alter any table in design mode....Let me know.
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
This is me opinion...for this purpose you can use a storedProcedure.
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Hi
I have written a project in C#.Net 2005 that is connected to SQL Server 2000. The SQL Server Engine is on a server and there are three clients connecting to this server. The application is running on clients. Each minute many requests such as select, insert and ... are sent to the server, through transactions. The default timeout of the SQL Server has not been changed. After 200 requests, for example (the number is random, sometimes more, sometimes less), an error occurs which is:
"Timeout expired, the timeout period elapsed prior to the completion of the operation or the server is not responding"
With no changes in the server name, firewall, network protocol or whatever, the next request after this error, will be sent correctly and the response will be got correctly. Can anyone help me to solve this problem?
Thanks in advance
|
|
|
|
|
I Dont knoq much about MSSQL, i know more MySQL
Do the uses have high response rate to each query?
How many connection can connect to MSSQL simutanosly?
Do you use Windows XP as OS? (Profesional version has a limit to 10 connections. there are some patches to increase that number)
|
|
|
|
|
Is your application connected to the database server on Local / remote environment?
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|