|
Genrally that means overly complicated.
As there is a built-in method in the string class that does what you ask for, you should obviously look at that before you look for anything "better".
As it turns out, the built-in method doesn't fulfill all your requirements, but it sure fulfills all the requirements that you mentioned in your original post.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa,
The "built-in method" -- you mean GetHashCode?
regards,
George
|
|
|
|
|
Yes.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Cool, Guffa!
regards,
George
|
|
|
|
|
Probably not, but George like to know his limits
|
|
|
|
|
Yeah its kinda crap
Well... its very very fast, uses some sort of parity method. You get collisions all the time though in fairly general usage.
|
|
|
|
|
Hi Mark,
Sorry I lost your context. Do you mean GetHashCode method?
regards,
George
|
|
|
|
|
Yep. GetHashCode is designed to be very fast. Tradeoff is that its also weak, poor dispersion, and not guaranteed to give you the same value over different versions of the framework.
It's basically for sorting keys into buckets for hashtables and that sort of thing.
|
|
|
|
|
Hi Mark!
1.
"not guaranteed to give you the same value over different versions of the framework" -- I think it is the main issue. Suppose we have hash value data generated by .Net 2.0 and then upgrade to 3.5, we need to upgrade both code and data. Correct?
2.
"not guaranteed to give you the same value over different versions of the framework." -- are there any official documents? I can not find any. It is appreciated if you could refer some.
regards,
George
|
|
|
|
|
Hi Guffa!
My concerns,
1. GetHashCode is random enough?
2. GetHashCode is not language independent and C# version independent? I want to find some standard way, which is platform/language independent, like CRC32, MD5 or something.
Any comments?
regards,
George
|
|
|
|
|
When maximize Form - i want to save the place and make them bigger
( proportionally ) - how can i do it in most easy way ??
|
|
|
|
|
Set the anchor properties of your controls to size as you want
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I set the anchor properties already - but first .. .its not working and the controls have any effect - and second ... when i comeback to check the anchor properties after running my application - then its come back the the value that was before i change it and i don't know why.
|
|
|
|
|
Try to Use "FlowLayOutPanel"
ToolBox ->Container
|
|
|
|
|
Hi.
I've found a ping example which I've been tryig do expand with a database etc, but I have one question:
When using the code below, I cant seem to get it to continue pinging - it just stops when "a host is not there".
Can anyone see how I can make it continue and just add the data "DNS Error" to the database?
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Threading;
using System.Data;
using System.Data.SqlClient;
namespace printHosts
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
}
SqlConnection oconn;
SqlCommand ocomm;
string sSql = "";
int ID = 0;
string address = "";
oconn = new SqlConnection(@"server=server;database=database;user id=user; password=password");
sSql = "SELECT hostname FROM Hostinfo";
ocomm = new SqlCommand(sSql);
SqlDataAdapter myapdater = new SqlDataAdapter(sSql, oconn);
DataSet ds = new DataSet("Hostinfo");
DataTable dataTable = ds.Tables["Hostinfo"];
myapdater.Fill(ds, "Hostinfo");
foreach (DataRow row in ds.Tables[0].Rows)
{
address = row["hostname"].ToString();
Console.WriteLine(address);
try
{
sSql = "SELECT COUNT(*) FROM Hostinfo WHERE hostname ='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
if (Convert.ToInt32(ocomm.ExecuteScalar()) == 0)
{
sSql = "INSERT INTO Hostinfo (hostname, currentPingTime) values "
+ "('" + row["hostname"].ToString() + "', '"
+ DateTime.Now + "', '"
+ "')";
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
sSql = "SELECT ID FROM Hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
}
else
{
sSql = "SELECT ID FROM Hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
sSql = "UPDATE Hostinfo SET "
+ "', LastPingTime ='" + ""
+ " WHERE id=" + ID;
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
}
oconn.Close();
}
catch
{
oconn.Open();
DateTime LastUpdatedPingTime = DateTime.Now;
sSql = "SELECT COUNT(*) FROM Hostinfo WHERE hostname ='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
if (Convert.ToInt32(ocomm.ExecuteScalar()) == 0)
{
sSql = "INSERT INTO Hostinfo (hostname, currentPingTime, repley) values"
+ "('" + row["hostname"].ToString() + "', '"
+ DateTime.Now + "', '"
+ address + "', '"
+ "')";
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
sSql = "SELECT ID FROM Hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
}
else
{
sSql = "SELECT ID FROM Hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
sSql = "UPDATE Hostinfo SET "
+ " currentPingTime ='" + DateTime.Now
+ "', repley ='" + address
+ "' WHERE id= '" + ID + "'"; ;
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
}
oconn.Close();
}
if (IsOffline())
{
return;
}
IPAddress ip = null;
try
{
ip = Dns.GetHostEntry(address).AddressList[0];
}
catch (System.Net.Sockets.SocketException ex)
{
Console.WriteLine("DNS Error: {0}", ex.Message);
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
return;
}
//Console.WriteLine("Pinging {0} [{1}] with 32 bytes of data:", address, ip.ToString());
Console.WriteLine();
Thread pingThread = new Thread(new ParameterizedThreadStart(StartPing));
pingThread.Start(ip);
pingThread.Join();
}
}
[Flags]
enum ConnectionState : int
{
INTERNET_CONNECTION_MODEM = 0x1,
INTERNET_CONNECTION_LAN = 0x2,
INTERNET_CONNECTION_PROXY = 0x4,
INTERNET_RAS_INSTALLED = 0x10,
INTERNET_CONNECTION_OFFLINE = 0x20,
INTERNET_CONNECTION_CONFIGURED = 0x40
}
[DllImport("wininet", CharSet = CharSet.Auto)]
static extern bool InternetGetConnectedState(ref ConnectionState lpdwFlags, int dwReserved);
static bool IsOffline()
{
ConnectionState state = 0;
InternetGetConnectedState(ref state, 0);
if (((int)ConnectionState.INTERNET_CONNECTION_OFFLINE & (int)state) != 0)
{
return true;
}
return false;
}
static void StartPing(object argument)
{
SqlConnection oconn;
SqlCommand ocomm;
string sSql = "";
int ID = 0;
string address = "";
try
{
oconn = new SqlConnection("server=sqlserver;database=audit_data;uid=user;pwd=password;");
oconn.Open();
sSql = "SELECT Hostname from hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
{
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
}
oconn.Close();
}
catch (Exception e)
{
}
IPAddress ip = (IPAddress)argument;
//set options ttl=128 and no fragmentation
PingOptions options = new PingOptions(128, true);
//create a Ping object
Ping ping = new Ping();
//32 empty bytes buffer
byte[] data = new byte[32];
int received = 0;
List<long> responseTimes = new List<long>();
//ping 4 times
for (int i = 0; i < 1; i++)
{
PingReply reply = ping.Send(ip, 1000, data, options);
if (reply != null)
{
switch (reply.Status)
{
case IPStatus.Success:
Console.WriteLine("Reply from {0}",
reply.Address, reply.Buffer.Length, reply.RoundtripTime, reply.Options.Ttl);
received++;
responseTimes.Add(reply.RoundtripTime);
break;
case IPStatus.TimedOut:
Console.WriteLine("Request timed out.");
break;
default:
Console.WriteLine("Ping failed {0}", reply.Status.ToString());
break;
}
}
else
{
Console.WriteLine("Ping failed for an unknown reason");
}
}
}
}
}
Thanks Jan.
|
|
|
|
|
While put Code please use proper format [ InlineCode ] and [Code Block]
that will be more understandable by all.
Thanks
|
|
|
|
|
Member 1541838 wrote: When using the code below, I cant seem to get it to continue pinging - it just stops when "a host is not there".
Member 1541838 wrote: for (int i = 0; i < 1; i++)
You need to learn how to use for loops. You loop will only iterate once...
|
|
|
|
|
Hi.
Do you have an example of what in the code:
"for (int i = 0; i < 1; i++)" I need to change and to what, to make it continue pinging the rest of the host from the host table?
\Jan.
|
|
|
|
|
HI,
I want draw a 3d chart in excell sheet using c# web based appliction .
Please give me an idea about this As soon as possible.
|
|
|
|
|
Murugan k wrote: I want draw a 3d chart in excell sheet using c# web based appliction
Then put it on asp.net forum
|
|
|
|
|
my system attacth to network. when i access to another pc that time open a new window to ask me user name and password. it is another problem. my probleam is i want to create a exe in C#.net. when this will execute the exe to connect another pc enter autometically enter the user name and password. how connect to another pc and put user name and password. i have been use below namespace.
system.net.sockets
system.net
|
|
|
|
|
Hi Rinki,
Are you trying to access the system or access any folder ?
if you dont have the access permission you have to provide the "Network Credentials [ Username, Password , Domain ]" , that why it was asking for username password .
Now what is your objective, just connect with pc or accesing some file?
|
|
|
|
|
no i m try to saying that i want to create exe in C#.net so that when execute the exe to connect network according to IP address and autometically enter the user name and password. last in how i connect network pc using by program. i had been use below namespace.
using.System.Net.Sockets
using.System.Net
|
|
|
|
|
hiiiiiiiiiiiiii
can any body help meeeeeeee
i want microsoft word document 2003 header files,
i want dll. function which it calling the header files using c# 2003 programming language
plz. help me
|
|
|
|
|
Hard to understand your post, but I THINK you want to use the Microsoft tools for office to create Word documents in C# ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|