|
That has the same exact issue as List<SecondClass>. All generic collections would have this issue.
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:08am.
|
|
|
|
|
Not really. If you just create a List<object>, that will work too... or if both classes derive from some other common type, that'd work too.
|
|
|
|
|
Create a base class (let's call it "MyBaseClass ") from which to derive FirstClass and SecondClass .
At that point, you can create
List<MyBaseClass> myList = new List<MyBaseClass>();
and then you can add any object derived from MyBaseClass to myList .
If you want to know how/why this works, use google..45 ACP - because shooting twice is just silly----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
modified on Saturday, February 27, 2010 2:21 PM
|
|
|
|
|
John, the HTML monster may have eaten part of your message. And a little () would be welcome too.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Ooops - fixed. .45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi My friends,
When you have a tabcontrol with some tabpages, how can browse tabpages automatically.
For example you located in tabpage3 and you need to go to tabpage4 after clicking a button.Best Regards,
Reza Shojaee
|
|
|
|
|
Hi,
use TabControl.SelectedTab or TabControl.SelectedIndex . It is all documented.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Luc Pattyn wrote: It is all documented.
Harumph... That's the same as saying "use google". .45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: That's the same as saying "use google".
Not really, there is no problem in locating the information. The only problem seems to be lack of willingness to read it.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Luc Pattyn wrote: The only problem seems to be lack of willingness to read it.
I don't think that's the only problem... .45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Cheer up, John; it can't be all that bad.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
You're right... It's worse. .45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I want to convert a .doc file to .txt file, can some body help me out. I tried with Stream Reader but iam getting Some Junk code in additon to Actual code....
|
|
|
|
|
|
... or read the documentation[^] and implement it yourself.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Hi everybody
What is the best method for storing passwords in SQL database through C# ?Best Regards,
Reza Shojaee
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:08am.
|
|
|
|
|
How can create MD5 hash in C#? Best Regards,
Reza Shojaee
|
|
|
|
|
|
Don't use MD5 - it is officially "broken". Use SHA instead. Attached the class I use for SHA handling:
using System;
using System.Text;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.Security;
using System.IO;
namespace UtilityControls
{
public class SHA2Hash
{
#region Fields
private byte[] _SHA2Data;
public const int SHA2Bits = 512;
public const int SHA2Bytes = SHA2Bits / 8;
public const int Length = SHA2Bytes * 2;
#endregion
#region Properties
public string SHA2data
{
get
{
StringBuilder sb = new StringBuilder(Length);
foreach (byte b in _SHA2Data)
{
sb.Append(b.ToString("x2"));
}
return sb.ToString();
}
}
#endregion
#region Constructors
public SHA2Hash(Stream s)
{
SHA512 shaM = new SHA512Managed();
_SHA2Data = shaM.ComputeHash(s);
}
public SHA2Hash(SecureString ss)
{
SHA512 shaM = new SHA512Managed();
if (ss != null)
{
IntPtr ptr = Marshal.SecureStringToBSTR(ss);
byte[] bs = Encoding.UTF8.GetBytes(Marshal.PtrToStringAuto(ptr));
_SHA2Data = shaM.ComputeHash(bs);
Marshal.ZeroFreeBSTR(ptr);
}
}
public SHA2Hash(string s)
{
SHA512 shaM = new SHA512Managed();
byte[] bs = Encoding.UTF8.GetBytes(s);
_SHA2Data = shaM.ComputeHash(bs);
}
public SHA2Hash(string s, bool bRestore)
{
if (!bRestore)
{
throw new ApplicationException("Invalid Restore Constructor parameter");
}
if (s.Length == SHA2Hash.Length)
{
byte[] bytes = new byte[SHA2Hash.SHA2Bytes];
char[] chars = s.ToCharArray();
int i = 0;
while ((i >= 0) && (i < SHA2Hash.SHA2Bytes))
{
if (StaticMethods.IsHex(chars[(i * 2) + 0]) && StaticMethods.IsHex(chars[(i * 2) + 1]))
{
byte b1 = StaticMethods.ByteHex(chars[(i * 2) + 0]);
byte b2 = StaticMethods.ByteHex(chars[(i * 2) + 1]);
bytes[i] = (byte) ((b1 << 4) | b2);
i++;
}
else
{
i = -1;
}
}
if (i > 0)
{
_SHA2Data = bytes;
return;
}
}
throw new ApplicationException("Bad restore hash data");
}
public SHA2Hash(byte[] bytes)
{
SHA512 shaM = new SHA512Managed();
_SHA2Data = shaM.ComputeHash(bytes);
}
public SHA2Hash(char[] chars)
{
SHA512 shaM = new SHA512Managed();
byte[] bs = Encoding.UTF8.GetBytes(chars);
_SHA2Data = shaM.ComputeHash(bs);
}
#endregion
#region Overrides
public override int GetHashCode()
{
int hash = 0;
for (int i = 0; i < SHA2Bytes; i += 4)
{
hash ^= StaticMethods.LittleEndian(_SHA2Data[i + 0],
_SHA2Data[i + 1],
_SHA2Data[i + 2],
_SHA2Data[i + 3]);
}
return base.GetHashCode() ^ hash;
}
public override bool Equals(object obj)
{
return (this == (SHA2Hash)obj);
}
#endregion
#region Public methods
public static bool operator ==(SHA2Hash m1, SHA2Hash m2)
{
if ((object)m1 == null)
{
if ((object)m2 == null)
{
return true;
}
}
if (((object)m1 == null) || ((object)m2 == null))
{
return false;
}
for (int i = 0; i < SHA2Bytes; i++)
{
if (m1._SHA2Data[i] != m2._SHA2Data[i])
{
return false;
}
}
return true;
}
public static bool operator !=(SHA2Hash m1, SHA2Hash m2)
{
if ((object)m1 == null)
{
if ((object)m2 == null)
{
return false;
}
}
if (((object)m1 == null) || ((object)m2 == null))
{
return true;
}
for (int i = 0; i < SHA2Bytes; i++)
{
if (m1._SHA2Data[i] != m2._SHA2Data[i])
{
return true;
}
}
return false;
}
#endregion
#region Private Methods
#endregion
}
}
[edit]Forgot to use "Encode...when pasting" option.[/edit]
[edit again]Missed the < of </pre>[/edit again]You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
modified on Saturday, February 27, 2010 7:51 AM
|
|
|
|
|
FYI, looks like you encoded your ending PRE tag. And you may want to specify a lang attribute on that PRE tag (though I'm sure the code will not be looked at... probably just copy/pasted... so perhaps that's a moot point).
|
|
|
|
|
Thanks Griff, just what I need. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
nice example.
thanks
|
|
|
|
|
You shouldn't use MD5 for new applications - it is officially "broken". Use SHA-512 instead, as it is currently ok until the SHA-1024 spec is released in 2012. You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|