本文整理汇总了C#中System.Collections.SortedList.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.Clear方法的具体用法?C# SortedList.Clear怎么用?C# SortedList.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.SortedList
的用法示例。
在下文中一共展示了SortedList.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestClearBasic
public void TestClearBasic()
{
StringBuilder sblMsg = new StringBuilder(99);
SortedList sl2 = null;
StringBuilder sbl3 = new StringBuilder(99);
StringBuilder sbl4 = new StringBuilder(99);
StringBuilder sblWork1 = new StringBuilder(99);
String s1 = null;
String s2 = null;
int i = 0;
//
// Constructor: Create SortedList using this as IComparer and default settings.
//
sl2 = new SortedList(this);
// Verify that the SortedList is not null.
Assert.NotNull(sl2);
// Verify that the SortedList is empty.
Assert.Equal(0, sl2.Count);
// now Clear the list and verify the Count
sl2.Clear(); //removes 0 element
Assert.Equal(0, sl2.Count);
// Testcase: add few key-val pairs
for (i = 0; i < 100; i++)
{
sblMsg.Length = 0;
sblMsg.Append("key_");
sblMsg.Append(i);
s1 = sblMsg.ToString();
sblMsg.Length = 0;
sblMsg.Append("val_");
sblMsg.Append(i);
s2 = sblMsg.ToString();
sl2.Add(s1, s2);
}
// now get the list Count and verify
Assert.Equal(100, sl2.Count);
// now Clear the list and verify the Count
sl2.Clear(); //removes all the 100 elements
Assert.Equal(0, sl2.Count);
}
示例2: calculateMatchRate
//return how closely an input string resembles a single memory entry
protected int calculateMatchRate(ArrayList input, ArrayList memory)
{
int matchRate = 0;
IEnumerator i = input.GetEnumerator();
IEnumerator m = memory.GetEnumerator();
while(i.MoveNext())
{
while(m.MoveNext())
{
SortedList isNewWord = new SortedList();
string cc = (string)i.Current;
string bb = (string)m.Current;
cc.ToLower();
bb.ToLower();
//mehrfachwertung für ein wort vermeiden z.b. eine 3 für 3x "ich"
if(!isNewWord.Contains(bb))
{
isNewWord.Add(bb, bb);
if(cc == bb)
{
matchRate++;
}
}
isNewWord.Clear();
}
}
return matchRate;
}
示例3: ProcessEmbeddedDevice
protected TreeNode ProcessEmbeddedDevice(UPnPDevice device)
{
SortedList TempList = new SortedList();
TreeNode Parent;
TreeNode Child;
Parent = new TreeNode(device.FriendlyName, 1, 1);
Parent.Tag = device;
/*
for(int x=0;x<device.Services.Length;++x)
{
device.Services[x].OnInvokeError += new UPnPService.UPnPServiceInvokeErrorHandler(HandleInvokeError);
device.Services[x].OnInvokeResponse += new UPnPService.UPnPServiceInvokeHandler(HandleInvoke);
}
*/
for (int cid = 0; cid < device.Services.Length; ++cid)
{
Child = new TreeNode(device.Services[cid].ServiceURN, 2, 2);
Child.Tag = device.Services[cid];
TreeNode stateVarNode = new TreeNode("State variables", 6, 6);
Child.Nodes.Add(stateVarNode);
UPnPStateVariable[] varList = device.Services[cid].GetStateVariables();
TempList.Clear();
foreach (UPnPStateVariable var in varList)
{
TreeNode varNode = new TreeNode(var.Name, 5, 5);
varNode.Tag = var;
TempList.Add(var.Name, varNode);
//stateVarNode.Nodes.Add(varNode);
}
IDictionaryEnumerator sve = TempList.GetEnumerator();
while (sve.MoveNext())
{
stateVarNode.Nodes.Add((TreeNode)sve.Value);
}
TempList.Clear();
foreach (UPnPAction action in device.Services[cid].GetActions())
{
string argsstr = "";
foreach (UPnPArgument arg in action.ArgumentList)
{
if (arg.IsReturnValue == false)
{
if (argsstr != "") argsstr += ", ";
argsstr += arg.RelatedStateVar.ValueType + " " + arg.Name;
}
}
TreeNode methodNode = new TreeNode(action.Name + "(" + argsstr + ")", 4, 4);
methodNode.Tag = action;
//Child.Nodes.Add(methodNode);
TempList.Add(action.Name, methodNode);
}
IDictionaryEnumerator ide = TempList.GetEnumerator();
while (ide.MoveNext())
{
Child.Nodes.Add((TreeNode)ide.Value);
}
Parent.Nodes.Add(Child);
}
for (int cid = 0; cid < device.EmbeddedDevices.Length; ++cid)
{
Child = ProcessEmbeddedDevice(device.EmbeddedDevices[cid]);
Child.Tag = device.EmbeddedDevices[cid];
Parent.Nodes.Add(Child);
}
return (Parent);
}
示例4: CheckPatchesConsistent
/// <summary>
/// see if any patches are missing; is there a direct line between FCurrentlyInstalledVersion and FLatestAvailablePatch?
/// </summary>
/// <returns>return a list of all patches that should be applied. empty list if there is a problem</returns>
public SortedList CheckPatchesConsistent(SortedList AOrderedListOfAllPatches)
{
SortedList ResultPatchList = new SortedList();
TFileVersionInfo testPatchVersion;
// get the latest patch that is available
FLatestAvailablePatch = new TFileVersionInfo(FCurrentlyInstalledVersion);
foreach (string patch in AOrderedListOfAllPatches.GetValueList())
{
testPatchVersion = TPatchFileVersionInfo.GetLatestPatchVersionFromDiffZipName(patch);
if (testPatchVersion.Compare(FLatestAvailablePatch) > 0)
{
FLatestAvailablePatch = testPatchVersion;
}
}
// drop unnecessary patch files
// ie. patch files leading to the same version, eg. 2.2.11-1 and 2.2.12-2 to 2.2.12-3
// we only want the biggest step
testPatchVersion = new TFileVersionInfo(FCurrentlyInstalledVersion);
bool patchesAvailable = true;
while (patchesAvailable)
{
StringCollection applyingPatches = new StringCollection();
foreach (string patch in AOrderedListOfAllPatches.GetValueList())
{
if (TPatchFileVersionInfo.PatchApplies(testPatchVersion, patch))
{
applyingPatches.Add(patch);
}
}
patchesAvailable = (applyingPatches.Count > 0);
if (applyingPatches.Count > 0)
{
// see which of the applying patches takes us further
string highestPatch = applyingPatches[0];
TFileVersionInfo highestPatchVersion = TPatchFileVersionInfo.GetLatestPatchVersionFromDiffZipName(highestPatch);
foreach (string patch in applyingPatches)
{
if (TPatchFileVersionInfo.GetLatestPatchVersionFromDiffZipName(patch).Compare(highestPatchVersion) > 0)
{
highestPatch = patch;
highestPatchVersion = TPatchFileVersionInfo.GetLatestPatchVersionFromDiffZipName(highestPatch);
}
}
ResultPatchList.Add(highestPatch, highestPatch);
testPatchVersion = highestPatchVersion;
}
}
if (FLatestAvailablePatch.Compare(testPatchVersion) != 0)
{
// check for a generic patch file, starting from version 0.0.99.99
foreach (string patch in AOrderedListOfAllPatches.GetValueList())
{
if (patch.Contains("0.0.99.99"))
{
testPatchVersion = TPatchFileVersionInfo.GetLatestPatchVersionFromDiffZipName(patch);
ResultPatchList.Clear();
ResultPatchList.Add(patch, patch);
}
}
}
if (FLatestAvailablePatch.Compare(testPatchVersion) != 0)
{
TLogging.Log("missing patchfile from version " + testPatchVersion.ToString() + " to " + FLatestAvailablePatch.ToString());
return new SortedList();
}
return ResultPatchList;
}
示例5: ClearDoesNotTouchCapacity
public void ClearDoesNotTouchCapacity ()
{
SortedList sl = new SortedList ();
// according to MSDN docs Clear () does not change capacity
for (int i = 0; i < 18; i++) {
sl.Add (i, i);
}
int capacityBeforeClear = sl.Capacity;
sl.Clear ();
int capacityAfterClear = sl.Capacity;
Assert.AreEqual (capacityBeforeClear, capacityAfterClear);
}
示例6: Clear_Capacity_Reset
public void Clear_Capacity_Reset ()
{
SortedList sl = new SortedList (0);
Assert.AreEqual (0, sl.Capacity, "#1");
sl.Clear ();
// reset to class default (16)
Assert.AreEqual (16, sl.Capacity, "#2");
sl.Capacity = 0;
Assert.AreEqual (16, sl.Capacity, "#3");
// note: we didn't return to 0 - so Clear cahnge the default capacity
}
示例7: TestClear
public void TestClear ()
{
SortedList sl1 = new SortedList (10);
sl1.Add ("kala", 'c');
sl1.Add ("kala2", 'd');
Assert.AreEqual (10, sl1.Capacity, "#A1");
Assert.AreEqual (2, sl1.Count, "#A2");
sl1.Clear ();
Assert.AreEqual (0, sl1.Count, "#B1");
#if !NET_2_0 // no such expectation as it is broken in .NET 2.0
Assert.AreEqual (16, sl1.Capacity, "#B2");
#endif
}
示例8: TestIndexOfValueBasic
public void TestIndexOfValueBasic()
{
StringBuilder sblMsg = new StringBuilder(99);
//
SortedList sl2 = null;
StringBuilder sbl3 = new StringBuilder(99);
StringBuilder sbl4 = new StringBuilder(99);
StringBuilder sblWork1 = new StringBuilder(99);
string s1 = null;
string s2 = null;
string s3 = null;
string s4 = null;
int i = 0;
int j = 0;
//
// Constructor: Create SortedList using this as IComparer and default settings.
//
sl2 = new SortedList(this);
// Verify that the SortedList is not null.
Assert.NotNull(sl2);
// Verify that the SortedList is empty.
Assert.Equal(0, sl2.Count);
// with null - should return -1
// null val
j = sl2.IndexOfValue((string)null);
Assert.Equal(-1, j);
// invalid val - should return -1
j = sl2.IndexOfValue("No_Such_Val");
Assert.Equal(-1, j);
// null is a valid value
sl2.Add("Key_0", null);
j = sl2.IndexOfValue(null);
Assert.NotEqual(-1, j);
// first occurrence check
sl2.Add("Key_1", "Val_Same");
sl2.Add("Key_2", "Val_Same");
j = sl2.IndexOfValue("Val_Same");
Assert.Equal(1, j);
sl2.Clear();
// Testcase: add few key-val pairs
for (i = 0; i < 100; i++)
{
sblMsg.Length = 0;
sblMsg.Append("key_");
sblMsg.Append(i);
s1 = sblMsg.ToString();
sblMsg.Length = 0;
sblMsg.Append("val_");
sblMsg.Append(i);
s2 = sblMsg.ToString();
sl2.Add(s1, s2);
}
//
// Testcase: test IndexOfVal
//
for (i = 0; i < sl2.Count; i++)
{
sblMsg.Length = 0;
sblMsg.Append("key_"); //key
sblMsg.Append(i);
s1 = sblMsg.ToString();
sblMsg.Length = 0;
sblMsg.Append("val_"); //value
sblMsg.Append(i);
s2 = sblMsg.ToString();
// now use IndexOfKey and IndexOfVal to obtain the same object and check
s3 = (string)sl2.GetByIndex(sl2.IndexOfKey(s1)); //Get the index of this key and then get object
s4 = (string)sl2.GetByIndex(sl2.IndexOfValue(s2)); //Get the index of this val and then get object
Assert.True(s3.Equals(s4));
// now Get using the index obtained thru IndexOfKey () and compare it with s2
s3 = (string)sl2.GetByIndex(sl2.IndexOfKey(s1));
Assert.True(s3.Equals(s2));
}
//
// Remove a key and then check
//
sblMsg.Length = 0;
sblMsg.Append("key_50");
s1 = sblMsg.ToString();
//.........这里部分代码省略.........
示例9: GetModuleRights
/// <summary>
/// 返回模块权限记录表
/// </summary>
/// <param name="ConnectInfo"></param>
/// <param name="UserCode"></param>
/// <returns></returns>
public SortedList GetModuleRights(String[] ConnectInfo,String UserCode,out DataTable returnDT)
{
//DataTable dt;
SortedList ModuleRightList=new SortedList();
int i;
CModuleRight tempModuleRight;;
try
{
ConnectInfo=ConnectInfo;
//读取该用户的模块权限
returnDT=this.GetModuleRightTable(UserCode);
ModuleRightList.Clear();
for(i=0;i<=returnDT.Rows.Count-1;i++)
{
tempModuleRight=new CModuleRight(ConnectInfo, returnDT.Rows[i]);
ModuleRightList.Add(tempModuleRight.ModuleCode,tempModuleRight); //模块编码做键值
}
return ModuleRightList;
}
catch(Exception ee)
{
//returnDT=null;
throw new Exception(ee.Message );
//return null;
}
}
示例10: UpdateRightDataTable
/// <summary>
/// 批量插入表中的所有数据
/// </summary>
/// <param name="TableName"></param>
/// <param name="FieldValueList"></param>
/// <param name="PrimaryKeyList"></param>
/// <returns></returns>
public void UpdateRightDataTable(string TableName, DataTable MyDataTable, string UserCode)
{
System.Data.SqlClient.SqlConnection conn;
System.Data.SqlClient.SqlDataAdapter dbAdpter; //数据适配器
System.Data.SqlClient.SqlCommand dbCommand; //数据操作命令
System.Data.SqlClient.SqlCommand dbCommand2; //数据操作命令
System.Data.SqlClient.SqlCommandBuilder dbCommandBuilder; //提供自动生成表单的命令方法
//System.Data.SqlClient.SqlTransaction tempTran;
DataRow dr;
SortedList tempForkeyList = new SortedList();
conn = new SqlConnection(mConnectInfo);
conn.Open();
//开始事务
//tempTran = conn.BeginTransaction();
dbCommand = new SqlCommand();
//dbCommand.Transaction =tempTran;
dbCommand.CommandText = "select * from " + TableName + " where za0100 is null";
dbCommand.Connection = conn;
dbCommand2 = new SqlCommand();
//dbCommand2.Transaction = tempTran;
dbCommand2.CommandText = "Delete from " + TableName + " where ZA0100='" + UserCode + "'";
dbCommand2.Connection = conn;
dbCommand2.ExecuteNonQuery();
dbAdpter = new SqlDataAdapter(dbCommand);
dbCommandBuilder = new SqlCommandBuilder(dbAdpter);
//dbAdpter.Fill(tempDT);
SortedList tempFieldValueList = new SortedList();
SortedList tempLocateList = new SortedList();
tempForkeyList.Add("ZA0100", UserCode);
//设置每行的ID值
for (int i = 0; i <= MyDataTable.Rows.Count - 1; i++)
{
MyDataTable.Rows[i][TableName + "ID"] = this.GetChildSetAddId(TableName, tempForkeyList);
dr = MyDataTable.Rows[i];
tempFieldValueList.Clear();
tempLocateList.Clear();
tempLocateList.Add("ZA0100", "1");
for (int j = 0; j <= MyDataTable.Columns.Count - 1; j++)
{
tempFieldValueList.Add(MyDataTable.Columns[j].ColumnName, dr[j]);
}
this.AddOneRec(TableName, tempFieldValueList, tempLocateList);
}
//dbAdpter.Update(MyDataTable);
//提交事务
//tempTran.Commit();
}//UpdataDataTable
示例11: GetSortedList
/// <summary>
/// Returns the sorted connection list.
/// </summary>
/// <returns></returns>
private SortedList<string, int> GetSortedList()
{
SortedList<string, int> Retval = new SortedList<string, int>();
try
{
int Index = 0;
foreach (DatabasePreference.OnlineConnectionDetail ConnectionDetail in this.OnlineDatabaseDetails)
{
if (ConnectionDetail.DIConnectionDetails.ServerType == DIServerType.MsAccess)
{
//-- In case of access, add the dbname only.
Retval.Add(Path.GetFileName(ConnectionDetail.DIConnectionDetails.DbName), Index);
}
else
{
//-- In case of other Db, add the connection name.
Retval.Add(ConnectionDetail.Connection, Index);
}
Index += 1;
}
}
catch (Exception ex)
{
Retval.Clear();
}
return Retval;
}
示例12: DataGridView1_SelectionChanged
private void DataGridView1_SelectionChanged(object sender, EventArgs e)
{
SortedList sList = new SortedList();
try
{
//ClearTextBox();
string packno = "";
int rCount = dgv_PackInfo.SelectedRows.Count;
if (rCount != 0)
{
for (int i = 0; i < rCount; i++)
{
sList.Add(int.Parse(dgv_PackInfo.SelectedRows[i].Cells[1].Value.ToString()), i);
}
}
if (sList.Count != 0)
{
foreach (int i in sList.Keys)
{
packno += i + "、";
}
packno = packno.Substring(0, packno.Length - 1);
txtCurPackage.Text = "第 "+ packno + " 包";
}
else
{
txtCurPackage.Text = "";
}
LoadPackList();
}
finally
{
sList.Clear();
GC.Collect();
}
}
示例13: MakeOidList
public static SortedList MakeOidList(int selectedIndex, PacketLog log, out int currentRegion, out int currentZone)
{
SortedList oidInfo = new SortedList();
currentRegion = -1;
currentZone = -1;
ushort playerOid = 0;
string CharName = "UNKNOWN";
for (int i = 0; i < selectedIndex; ++i)
{
Packet pak = log[i];
if (pak is StoC_0xD4_PlayerCreate)
{
StoC_0xD4_PlayerCreate player = (StoC_0xD4_PlayerCreate)pak;
oidInfo[player.Oid] = new LivingInfo(pak.Time, "PLR", player.Name, player.Level, player.GuildName);
}
else if (pak is StoC_0x4B_PlayerCreate_172)
{
StoC_0x4B_PlayerCreate_172 player = (StoC_0x4B_PlayerCreate_172)pak;
oidInfo[player.Oid] = new LivingInfo(pak.Time, "PLR", player.Name, player.Level, player.GuildName);
if (currentZone == -1)
currentZone = player.ZoneId;
}
else if (pak is StoC_0x12_CreateMovingObject)
{
StoC_0x12_CreateMovingObject obj = (StoC_0x12_CreateMovingObject)pak;
oidInfo[obj.ObjectOid] = new ObjectInfo(pak.Time, "MOVE", obj.Name, 0);
}
else if (pak is StoC_0x6C_KeepComponentOverview)
{
StoC_0x6C_KeepComponentOverview keep = (StoC_0x6C_KeepComponentOverview)pak;
oidInfo[keep.Uid] = new ObjectInfo(pak.Time, "Keep", string.Format("keepId:0x{0:X4} componentId:{1}", keep.KeepId, keep.ComponentId), 0);
}
else if (pak is StoC_0xD1_HouseCreate)
{
StoC_0xD1_HouseCreate house = (StoC_0xD1_HouseCreate)pak;
oidInfo[house.HouseId] = new ObjectInfo(pak.Time, "HOUS", house.Name, 0);
}
else if (pak is StoC_0xDA_NpcCreate)
{
StoC_0xDA_NpcCreate npc = (StoC_0xDA_NpcCreate)pak;
oidInfo[npc.Oid] = new LivingInfo(pak.Time, "NPC", npc.Name, npc.Level, npc.GuildName);
}
else if (pak is CtoS_0xA9_PlayerPosition)
{
CtoS_0xA9_PlayerPosition plr = (CtoS_0xA9_PlayerPosition)pak;
if (currentZone == -1)
currentZone = plr.CurrentZoneId;
}
else if (pak is StoC_0xD9_ItemDoorCreate)
{
StoC_0xD9_ItemDoorCreate item = (StoC_0xD9_ItemDoorCreate)pak;
string type = "ITEM";
if (item.ExtraBytes > 0) type = "DOOR";
oidInfo[item.Oid] = new ObjectInfo(pak.Time, type, item.Name, 0);
}
else if (pak is StoC_0xB7_RegionChange)
{
StoC_0xB7_RegionChange region = (StoC_0xB7_RegionChange)pak;
// if (region.RegionId != currentRegion)
// {
currentRegion = region.RegionId;
currentZone = region.ZoneId;
oidInfo.Clear();
// }
}
else if (pak is StoC_0x20_PlayerPositionAndObjectID_171)
{
StoC_0x20_PlayerPositionAndObjectID_171 region = (StoC_0x20_PlayerPositionAndObjectID_171)pak;
// if (region.Region!= currentRegion)
// {
currentRegion = region.Region;
oidInfo.Clear();
// }
playerOid = region.PlayerOid;
oidInfo[region.PlayerOid] = new LivingInfo(pak.Time, "YOU", CharName, 0, "");
}
else if (pak is StoC_0x16_VariousUpdate)
{
if (playerOid != 0)
{
StoC_0x16_VariousUpdate stat = (StoC_0x16_VariousUpdate)pak;
if (stat.SubCode == 3)
{
StoC_0x16_VariousUpdate.PlayerUpdate subData = (StoC_0x16_VariousUpdate.PlayerUpdate)stat.SubData;
if (oidInfo[playerOid] != null)
{
LivingInfo plr = (LivingInfo)oidInfo[playerOid];
plr.level = subData.playerLevel;
plr.guildName = subData.guildName;
oidInfo[playerOid] = plr;
}
//.........这里部分代码省略.........
示例14: btn_p5_termList_Click
private void btn_p5_termList_Click(object sender, EventArgs e)
{
string line = "", Term = "", POS = "", DocNO_tag = ""; //資料列, 詞彙, 詞性標記
int index = 0, value = 0, pt = 0;
StringBuilder SB5 = new StringBuilder();
List<string> temp_list = new List<string>();
SortedList Term_DF_slist = new SortedList(); //整個文件集之"詞彙列表" 及詞會出現次數 DF
List<KeyValuePair<string, int>> Doctermtf_list = new List<KeyValuePair<string, int>>(); //-記錄每篇文件出現之詞彙集詞頻 -
// if ((openFileDialog1.ShowDialog() == DialogResult.OK) && ((txt_p5_fileName.Text = openFileDialog1.FileName) != null)) //開啟Window開啟檔案管理對話視窗
//{
using (StreamReader myTextFileReader = new StreamReader(@txt_p5_fileName.Text, Encoding.Default))
{
SortedList DocTermTF_slist = new SortedList(); //暫存每篇文件之"詞彙列表" 及詞會出現次數 TF
// ---- 處理文件集中的每一篇文件與文件中的所有詞彙 (詞彙列表 ,計算 TF , 計算 DF)----
while (myTextFileReader.EndOfStream != true) //非資料檔案結尾
{
line = (myTextFileReader.ReadLine().Trim()) + " ";
// ----- 若為一篇新文件的開始
if (line.Contains("<DocNo>"))
{
TotalDocNum++;
DocNO_tag = line.Substring(line.IndexOf("<DocNo>"), ((line.IndexOf("</DocNo>") + 8) - line.IndexOf("<DocNo>")));
//line = line.Remove(line.IndexOf("<DocNo>"), ((line.IndexOf("</DocNo>") + 8) - line.IndexOf("<DocNo>")));
// -------------------------------------- 計算詞彙之 DF ---------------------------------------------------
if (temp_list.Count != 0)
{
foreach (string str in temp_list) //複製與計算出現在每一文件之詞彙的"DF"
{
//-- 計算詞彙之 DF --
if ((index = Term_DF_slist.IndexOfKey(str)) != -1) //在termList中找尋特定的Term,若Term不存在怎則傳回-1
{
value = (int)Term_DF_slist.GetByIndex(index);
value++; //該term存在,則term的出現次數加1
Term_DF_slist.SetByIndex(index, value);
}
else
Term_DF_slist.Add(str, 1); //該詞彙(term)不存在於termList中,則加入該新詞彙(term)
}
temp_list.Clear(); //清除紀錄每一篇文件內之詞彙的SortedList
}
//--------------記錄每篇文件出現之詞彙集詞頻 -Doctermtf_list -----------
if (DocTermTF_slist.Count != 0)
{
foreach (DictionaryEntry obj in DocTermTF_slist)
{
KeyValuePair<string, int> x = new KeyValuePair<string, int>((string)obj.Key, (int)obj.Value);
Doctermtf_list.Add(x);
}
DocTermTF_slist.Clear();
}
KeyValuePair<string, int> x1 = new KeyValuePair<string, int>(DocNO_tag, 0); //加入文件編號標籤
Doctermtf_list.Add(x1);
continue;
}
// ---------------------------------- 記錄並產生整個文件集之"詞彙列表" 及詞會出現次數 TF------------------------------------------
string[] terms = line.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string str in terms)
{
if (str.IndexOf("(") == -1 || str.IndexOf(")") == -1) //找不到'()',就不處理/
continue;
Term = str.Substring(0, str.IndexOf("("));
POS = str.Substring(str.IndexOf("("));
if (Term.Length != 0) //若有"詞彙"存在
{
//--- 記錄每篇文件之詞彙及其出現次數 ---
if ((pt = DocTermTF_slist.IndexOfKey((Term + POS))) != -1)
{
value = (int)DocTermTF_slist.GetByIndex(pt);
value++; //該term存在,則term的出現次數加1
DocTermTF_slist.SetByIndex(pt, value); //紀錄整個文件集之"詞彙列表" 及詞會出現次數 TF
}
else
DocTermTF_slist.Add((Term + POS), 1); //該詞彙(term)不存在於termList中,則加入該新詞彙(term)
// --- 紀錄出現在每一文件之詞彙有哪些,用於計算詞彙之DF
if ((index = temp_list.IndexOf((Term + POS))) == -1)
temp_list.Add((Term + POS)); //紀錄出現在每一文件之詞彙有哪些,用於計算詞彙之DF
}
}
//TF詞頻比較
if (Doctermtf_list.Count != 0)
{
foreach (KeyValuePair<string, int> kvp in Doctermtf_list)
{
//KeyValuePair<string, int> x = new KeyValuePair<string, int>((string)obj.Key, (int)obj.Value);
}
}
}//End of while每一文件
// ----記錄並計算最後一篇文件之詞彙 DF --------
if (temp_list.Count != 0)
{
foreach (string str in temp_list) //複製與計算出現在每一文件之詞彙的"DF"
{
//.........这里部分代码省略.........
示例15: but_eliminar_libro_Click
private void but_eliminar_libro_Click(object sender, EventArgs e)
{
StringBuilder errorMessages = new StringBuilder();
Libro lib = new Libro();
if (tex_isbn.Text.Length == 0)
{
this.inicializarDatos();
MessageBox.Show("Debe ingresar un ISBN",
"Eliminar Libro",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
else
{
try
{
lib.v_isbn = tex_isbn.Text;
if ((lib.ConsultarLibro(lib)).v_isbn.Length != 0)
{
tex_isbn.Text = lib.v_isbn;
tex_titulo.Text = lib.v_titulo;
tex_edicion.Text = lib.v_edicion;
tex_autor.Text = lib.v_autor;
tex_año.Text = lib.v_año;
SLeditorial = new SortedList();
SLeditorial.Add(lib.v_Deditorial, lib.v_Deditorial);
com_editorial.DataSource = SLeditorial.GetValueList();
com_editorial.Show();
com_editorial.Enabled = false;
SLeditorial.Clear();
SLtipolibro = new SortedList();
SLtipolibro.Add(lib.v_Dtipo_libro, lib.v_Dtipo_libro);
com_tipo_libro.DataSource = SLtipolibro.GetValueList();
com_tipo_libro.Show();
com_tipo_libro.Enabled = false;
SLtipolibro.Clear();
SLidioma = new SortedList();
SLidioma.Add(lib.v_Didioma, lib.v_Didioma);
com_idioma.DataSource = SLidioma.GetValueList();
com_idioma.Show();
com_idioma.Enabled = false;
SLidioma.Clear();
lib.v_usuario_m = this.usuario;
if ((MessageBox.Show("¿Desea eliminar el Libro con Titulo: " + lib.v_titulo + " ?", "Eliminar Libro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes))
{
try
{
if (lib.EliminarLibro(lib) != 0)
{
this.inicializarDatos();
MessageBox.Show("Libro eliminada correctamente",
"Eliminar Libro",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
catch (SqlException ex)
{
for (int i = 0; i < ex.Errors.Count; i++)
{
errorMessages.Append("Index #" + i + "\n" +
"Message: " + ex.Errors[i].Message + "\n" +
"LineNumber: " + ex.Errors[i].LineNumber + "\n" +
"Source: " + ex.Errors[i].Source + "\n" +
"Procedure: " + ex.Errors[i].Procedure + "\n");
}
Console.WriteLine(errorMessages.ToString());
this.inicializarDatos();
MessageBox.Show(ex.Errors[0].Message.ToString(),
"Eliminar Libro",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
}
}
}
catch (SqlException ex)
{
for (int i = 0; i < ex.Errors.Count; i++)
{
errorMessages.Append("Index #" + i + "\n" +
"Message: " + ex.Errors[i].Message + "\n" +
"LineNumber: " + ex.Errors[i].LineNumber + "\n" +
"Source: " + ex.Errors[i].Source + "\n" +
"Procedure: " + ex.Errors[i].Procedure + "\n");
}
Console.WriteLine(errorMessages.ToString());
this.inicializarDatos();
MessageBox.Show(ex.Errors[0].Message.ToString(),
"Eliminar Libro",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
//.........这里部分代码省略.........