-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBase.cs
More file actions
72 lines (63 loc) · 1.74 KB
/
Base.cs
File metadata and controls
72 lines (63 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Created by SharpDevelop.
* User: Administrator
* Date: 2011-1-19
* Time: 16:38
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
//using System;
//using System.Collections;
//using System.Collections.Generic;
namespace eflayMH_WPF
{
/// <summary>
/// 扩展方法
/// </summary>
public static class Extension
{
/// <summary>
/// 比较两个数组内容是否相等
/// </summary>
/// <param name="b1">数组1</param>
/// <param name="b2">数组2</param>
/// <returns>是否相等</returns>
//public static bool Equals <T> (T[] b1, T[] b2)
//{
// if (b1.Length != b2.Length) return false;
// if (b1 == null || b2 == null) return false;
// for (int i = 0; i < b1.Length; i++)
// if (!b1[i].Equals( b2[i]))
// return false;
// return true;
//}
public static bool ArrayEquals( byte[] b1, byte[] b2)
{
if (b1.Length != b2.Length) return false;
if (b1 == null || b2 == null) return false;
for (int i = 0; i < b1.Length; i++)
if (!b1[i].Equals(b2[i]))
return false;
return true;
}
// 在 s 中查找 pattern 。
// 如果找到,返回 pattern 在 s 中第一次出现的位置(0起始)。
// 如果没找到,返回 -1。
//static int IndexOf<T>(T[] s, T[] pattern)
static int IndexOf(byte[] s, byte[] pattern)
{
int slen = s.Length;
int plen = pattern.Length;
for (int i = 0; i <= slen - plen; i++)
{
for (int j = 0; j < plen; j++)
{
if (!s[i + j].Equals(pattern[j])) goto next;
}
return i;
next:;
}
return -1;
}
}
}