Posts
[Performance][C#]絕對值的取得
namespace WindowsFormsApplication35 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
static int ABS1(int value) { return value < 0 ? -value : value; } static int ABS2(int value) { return Math.Abs(value); } private void button1_Click(object sender, EventArgs e) { int count = (int)numericUpDown1.Value; int value = -1; textBox1.AppendText("Count: " + count.ToString() + Environment.NewLine); Stopwatch sw = Stopwatch.StartNew(); for (int idx = 0; idx < count; ++idx) ABS1(value); sw.
read morePosts
[VB.NET]ASCII String與Hex String的互轉
Public Function AsciiStringToHexString(ByVal asciiString As String) As String Dim ascii() As Byte = System.Text.Encoding.Default.GetBytes(asciiString) Dim count As Integer = ascii.Length Dim hexArray(count - 1) As String For idx As Integer = 0 To count - 1 hexArray(idx) = ascii(idx).ToString("x2") Next Return String.Join(" ", hexArray) End Function Public Function HexStringToAsciiString(ByVal hexString As String) As String Dim array() As String = hexString.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries) For idx As Integer = 0 To array.
read morePosts
[VB.NET]MFC CArchive的讀取
#Region “Config” Private ReadOnly BYTES_COUNT_IN_BOOL As Byte = 4 ‘VC6的BOOL佔 4 Bytes Private ReadOnly BYTES_COUNT_IN_INT As Byte = 4 ‘VC6的Int佔 4 Bytes Private ReadOnly BYTES_COUNT_IN_FLOAT As Byte = 4 ‘VC6的Float佔 4 Bytes Private ReadOnly BYTES_COUNT_IN_DOUBLE As Byte = 8 ‘VC6的Double佔 8 Bytes Private ReadOnly BUFFERSIZE As Integer = 512
#End Region
#Region “Private Var”
Private m_baryBinaryData(BUFFERSIZE) As Byte Private m_fsFileStream As FileStream Private m_nDataLength As Integer Private m_strData As String Private m_nData As Integer Private m_sData As Single Private m_dData As Double Private m_bData As Boolean #End Region
read morePosts
[Performance]Set Form's Position
Dim _f As New Form Private Sub btnSetByPoint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetByPoint.Click _f.Show() Dim sw As Stopwatch = Stopwatch.StartNew For i As Integer = 0 To NumericUpDown1.Value _f.Location = New Point(10, 10) Next sw.Stop() _f.Hide() MsgBox("SetByPoint: " & sw.ElapsedMilliseconds.ToString) End Sub Private Sub btnSetByProperty_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetByProperty.Click _f.Show() Dim sw As Stopwatch = Stopwatch.StartNew For i As Integer = 0 To NumericUpDown1.
read more