19216810047
سه شنبه 11 تیر 1392, 14:14 عصر
با سلام
میشه توضیح بدید کد زیر چه کار می کنه؟
با تشکر
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
namespace RegularExpression
{
/// <summary>
/// this class Map many Value object to one Key object (one-to-many).
/// Example:
/// private Map map = new Map();
/// map.Add(".txt", "notepad.exe");
/// map.Add(".txt", "wordpad.exe");
/// map.Add(".jpg", "ie.exe");
/// map.Add(".jpg", "paint.exe");
///
/// NFA.Set setProgram = map[".txt"]; // get value is always a NFA.Set
///
/// </summary>
public class Map : Hashtable
{
public override void Add(object key, object mapTo)
{
Set set = null;
if (base.Contains(key) == true)
{
set = (Set)base[key];
}
else
{
set = new Set();
}
set.AddElement(mapTo);
base[key] = set;
}
public override object this[object key]
{
get
{
return base[key];
}
set
{
//base[key] = value;
Add(key, value);
}
}
}
}
کلاس set:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace RegularExpression
{
/// <summary>
/// this class represent a Set in Mathmatics, nothing else.
/// Since .NET does not have any built-in class for Set, I decided to create one myself.
/// Since this programm does many Set opertions, this class will help writing clean code
/// Many of the methods of this class have not been used in this program.
/// </summary>
public class Set : CollectionBase
{
public object this[int index]
{
get
{
return ((object)List[index]);
}
set
{
List[index] = value;
}
}
public int AddElement(object element)
{
if (Contains(element) == false)
{
return List.Add(element);
}
return -1;
}
public void AddElementRange(object[] arrValue)
{
foreach (object obj in arrValue)
{
if (Contains(obj) == false)
{
List.Add(obj);
}
}
}
public void Union(Set setValue)
{
foreach (object obj in setValue)
{
if (Contains(obj) == false)
{
List.Add(obj);
}
}
}
public bool IsSubset(Set setValue)
{
foreach (object obj in setValue)
{
if (Contains(obj) == false)
{
return false;
}
}
return true;
}
public bool IsProperSubset(Set setValue)
{
if (GetCardinality() > setValue.GetCardinality() && IsSubset(setValue) )
{
return true;
}
return false;
}
public void Subtract(Set setValue)
{
foreach (object obj in setValue)
{
if (Contains(obj) == true)
{
RemoveElement(obj);
}
}
}
public bool IsEqual(Set setValue)
{
if (GetCardinality() == setValue.GetCardinality() && IsSubset(setValue))
{
return true;
}
return false;
}
public bool IsEmpty()
{
return List.Count == 0 ? true : false;
}
public int GetCardinality()
{
return List.Count;
}
public bool ElementExist(object value)
{
return Contains(value);
}
public int IndexOf(object value)
{
return (List.IndexOf(value));
}
public bool RemoveElement(object value)
{
if (Contains(value) == true)
{
List.Remove(value);
return true;
}
return false;
}
private bool Contains(object value)
{
// If value is not of type Int16, this will return false.
return List.Contains(value);
}
protected override void OnInsert(int index, object value)
{
if (value == null)
{
throw new ArgumentException("Element cannot not be null.");
}
if (Contains(value) == true )
{
throw new ArgumentException("Element already exists in the set.", "value: " + value.ToString());
}
}
public Array ToArray(Type type)
{
return base.InnerList.ToArray(type);
}
}
}
ممنون می شم یه توضیح مختصر بدید.
میشه توضیح بدید کد زیر چه کار می کنه؟
با تشکر
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
namespace RegularExpression
{
/// <summary>
/// this class Map many Value object to one Key object (one-to-many).
/// Example:
/// private Map map = new Map();
/// map.Add(".txt", "notepad.exe");
/// map.Add(".txt", "wordpad.exe");
/// map.Add(".jpg", "ie.exe");
/// map.Add(".jpg", "paint.exe");
///
/// NFA.Set setProgram = map[".txt"]; // get value is always a NFA.Set
///
/// </summary>
public class Map : Hashtable
{
public override void Add(object key, object mapTo)
{
Set set = null;
if (base.Contains(key) == true)
{
set = (Set)base[key];
}
else
{
set = new Set();
}
set.AddElement(mapTo);
base[key] = set;
}
public override object this[object key]
{
get
{
return base[key];
}
set
{
//base[key] = value;
Add(key, value);
}
}
}
}
کلاس set:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace RegularExpression
{
/// <summary>
/// this class represent a Set in Mathmatics, nothing else.
/// Since .NET does not have any built-in class for Set, I decided to create one myself.
/// Since this programm does many Set opertions, this class will help writing clean code
/// Many of the methods of this class have not been used in this program.
/// </summary>
public class Set : CollectionBase
{
public object this[int index]
{
get
{
return ((object)List[index]);
}
set
{
List[index] = value;
}
}
public int AddElement(object element)
{
if (Contains(element) == false)
{
return List.Add(element);
}
return -1;
}
public void AddElementRange(object[] arrValue)
{
foreach (object obj in arrValue)
{
if (Contains(obj) == false)
{
List.Add(obj);
}
}
}
public void Union(Set setValue)
{
foreach (object obj in setValue)
{
if (Contains(obj) == false)
{
List.Add(obj);
}
}
}
public bool IsSubset(Set setValue)
{
foreach (object obj in setValue)
{
if (Contains(obj) == false)
{
return false;
}
}
return true;
}
public bool IsProperSubset(Set setValue)
{
if (GetCardinality() > setValue.GetCardinality() && IsSubset(setValue) )
{
return true;
}
return false;
}
public void Subtract(Set setValue)
{
foreach (object obj in setValue)
{
if (Contains(obj) == true)
{
RemoveElement(obj);
}
}
}
public bool IsEqual(Set setValue)
{
if (GetCardinality() == setValue.GetCardinality() && IsSubset(setValue))
{
return true;
}
return false;
}
public bool IsEmpty()
{
return List.Count == 0 ? true : false;
}
public int GetCardinality()
{
return List.Count;
}
public bool ElementExist(object value)
{
return Contains(value);
}
public int IndexOf(object value)
{
return (List.IndexOf(value));
}
public bool RemoveElement(object value)
{
if (Contains(value) == true)
{
List.Remove(value);
return true;
}
return false;
}
private bool Contains(object value)
{
// If value is not of type Int16, this will return false.
return List.Contains(value);
}
protected override void OnInsert(int index, object value)
{
if (value == null)
{
throw new ArgumentException("Element cannot not be null.");
}
if (Contains(value) == true )
{
throw new ArgumentException("Element already exists in the set.", "value: " + value.ToString());
}
}
public Array ToArray(Type type)
{
return base.InnerList.ToArray(type);
}
}
}
ممنون می شم یه توضیح مختصر بدید.