本文整理汇总了C#中Set.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# Set.ToArray方法的具体用法?C# Set.ToArray怎么用?C# Set.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Set
的用法示例。
在下文中一共展示了Set.ToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: addbiggerCliQ
private void addbiggerCliQ(List<Set<int>> ans, Set<int> curr, Set<int> inter)
{
int last = curr[curr.Count - 1];
for (int i = 0; i < inter.Count; i++)
{
int ind_inter = inter[i];
if (last < ind_inter)
{
Set<int> c = new Set<int>(curr.ToArray());
c.Add(ind_inter);
ans.Add(c);
}
}
}
示例2: SetActivePlugins
/// <summary>
/// Commits any changes made to plugin activation status.
/// </summary>
/// <param name="p_setActivePlugins">The complete set of active plugins.</param>
public override void SetActivePlugins(Set<string> p_setActivePlugins)
{
var strPluginsFilePath = ((Fallout3GameMode) Program.GameMode).PluginsFilePath;
var setPluginFilenames = new Set<string>(StringComparer.InvariantCultureIgnoreCase);
foreach (var strPlugin in p_setActivePlugins)
{
setPluginFilenames.Add(Path.GetFileName(strPlugin));
}
if (!Directory.Exists(Path.GetDirectoryName(strPluginsFilePath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(strPluginsFilePath));
}
File.WriteAllLines(strPluginsFilePath, setPluginFilenames.ToArray(), Encoding.Default);
}
示例3: BuildMatrixAAdjInfo
public int[][] BuildMatrixAAdjInfo(SparseMatrix A)
{
if (A == null)
throw new Exception("A matrix is null");
int[][] adj = new int[A.ColumnSize][];
Set<int> s = new Set<int>();
for (int i = 0; i < A.ColumnSize; i++)
{
s.Clear();
List<SparseMatrix.Element> col = A.Columns[i];
foreach (SparseMatrix.Element e in col)
{
List<SparseMatrix.Element> row = A.Rows[e.i];
foreach (SparseMatrix.Element e2 in row)
s.Add(e2.j);
}
adj[i] = s.ToArray();
}
return adj;
}
示例4: Main
static void Main(string[] args)
{
Set<TestClass> mySet = new Set<TestClass>();
HashSet<TestClass> systemSet = new HashSet<TestClass>();
for (int i = 0; i < 10000000; i++)
{
TestClass a = new TestClass(rand.Next(0, 100));
mySet.Add(a);
systemSet.Add(a);
TestClass b = new TestClass(rand.Next(0, 100));
mySet.Remove(b);
systemSet.Remove(b);
}
TestClass[] systemSetArray = systemSet.ToArray();
Array.Sort(systemSetArray);
TestClass[] mySetArray = mySet.ToArray();
Console.WriteLine(systemSetArray.SequenceEqual(mySetArray) ?
"test passed" : "test failed");
}
示例5: ContainsInvalidPathChars
/// <summary>
/// Determines if the given path contains invalid characters.
/// </summary>
/// <param name="p_strPath">The path to examine.</param>
/// <returns><c>true</c> if the given path contains invalid characters;
/// <c>false</c> otherwise.</returns>
public static bool ContainsInvalidPathChars(string p_strPath)
{
if (String.IsNullOrEmpty(p_strPath))
return false;
Set<string> setChars = new Set<string>();
string strPath = Path.GetDirectoryName(p_strPath);
if (!String.IsNullOrEmpty(strPath))
{
foreach (char chrInvalidChar in Path.GetInvalidPathChars())
setChars.Add("\\x" + ((Int32)chrInvalidChar).ToString("x2"));
Regex rgxInvalidPath = new Regex("[" + String.Join("", setChars.ToArray()) + "]");
if (rgxInvalidPath.IsMatch(strPath))
return true;
}
string strFile = Path.GetFileName(p_strPath);
if (String.IsNullOrEmpty(strPath))
return false;
setChars.Clear();
foreach (char chrInvalidChar in Path.GetInvalidFileNameChars())
setChars.Add("\\x" + ((Int32)chrInvalidChar).ToString("x2"));
Regex rgxInvalidFile = new Regex("[" + String.Join("", setChars.ToArray()) + "]");
return rgxInvalidFile.IsMatch(strFile);
}
示例6: GetAllXficsPossiblyAffectedByTagging
/// <summary>
/// Given a set of wfics, return the set of xfics that may be affected
/// by tagging or undoing the applied tag (which may overlap other xfics).
/// </summary>
/// <param name="hvoWfics"></param>
/// <returns></returns>
private Set<int> GetAllXficsPossiblyAffectedByTagging(List<int> hvoWfics)
{
// This is overkill, but there are too many cases to handle during undo/redo
// to cover with just CheckForOverlappingTags().
// For now get all the xfics for the segments owning the given wfics
// so we can make sure the display will be properly updated.
Set<int> segments = new Set<int>();
foreach (int hvoWfic in hvoWfics)
{
// first collect a list of parent segments.
StTxtPara.TwficInfo ti = new StTxtPara.TwficInfo(Cache, hvoWfic);
if (ti.SegmentHvo == 0)
continue;
segments.Add(ti.SegmentHvo);
}
// now get all the xfics for those segments
Set<int> allPossiblyAffectedXfics = new Set<int>();
allPossiblyAffectedXfics.AddRange((m_vc as InterlinTaggingVc).CollectXficsFromSegments(segments.ToArray()));
return allPossiblyAffectedXfics;
}
示例7: MergeTwoArrays
/// <summary>
/// Make an array which contains all the members of first() plus those of second() that
/// are not included in first.
/// </summary>
/// <param name="first"></param>
/// <param name="second"></param>
/// <returns></returns>
public static int[] MergeTwoArrays(int[] first, int[] second)
{
Set<int> set = new Set<int>(first);
set.AddRange(second);
return set.ToArray();
}
示例8: CreateSandbox
/// <summary>
/// Creates a sandboxed domain.
/// </summary>
/// <remarks>
/// The sandboxed domain is only given permission to alter the parts of the system
/// that are relevant to mod management for the current game mode.
/// </remarks>
/// <param name="p_scpScript">The script we are going to execute. This is required so we can include
/// the folder containing the script's script type class in the sandboxes PrivateBinPath.
/// We need to do this so that any helper classes and libraries used by the script
/// can be found.</param>
/// <returns>A sandboxed domain.</returns>
protected AppDomain CreateSandbox(IScript p_scpScript)
{
Trace.TraceInformation("Creating C# Script Sandbox...");
Trace.Indent();
Evidence eviSecurityInfo = null;
AppDomainSetup adsInfo = new AppDomainSetup();
//should this be different from the current ApplicationBase?
adsInfo.ApplicationBase = Path.GetDirectoryName(Application.ExecutablePath);
Set<string> setPaths = new Set<string>(StringComparer.OrdinalIgnoreCase);
Type tpeBaseScript = BaseScriptType;
while ((tpeBaseScript != null) && (tpeBaseScript != typeof(object)))
{
setPaths.Add(Path.GetDirectoryName(Assembly.GetAssembly(tpeBaseScript).Location));
tpeBaseScript = tpeBaseScript.BaseType;
}
Type tpeScript = p_scpScript.Type.GetType();
while ((tpeScript != null) && (tpeScript != typeof(object)))
{
setPaths.Add(Path.GetDirectoryName(Assembly.GetAssembly(tpeScript).Location));
tpeScript = tpeScript.BaseType;
}
adsInfo.PrivateBinPath = String.Join(";", setPaths.ToArray());
Trace.TraceInformation("ApplicationBase: {0}", adsInfo.ApplicationBase);
Trace.TraceInformation("PrivateBinPath: {0}", adsInfo.PrivateBinPath);
adsInfo.ApplicationName = "ScriptRunner";
adsInfo.DisallowBindingRedirects = true;
adsInfo.DisallowCodeDownload = true;
adsInfo.DisallowPublisherPolicy = true;
PermissionSet pstGrantSet = new PermissionSet(PermissionState.None);
pstGrantSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.PathDiscovery, Path.GetDirectoryName(Application.ExecutablePath)));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, Path.GetDirectoryName(Application.ExecutablePath)));
pstGrantSet.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess));
#if DEBUG
//this is unsafe, and should only be used to view exceptions inside the sandbox
pstGrantSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlEvidence));
pstGrantSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlPolicy));
#endif
//It's not clear to me if these permissions are dangerous
pstGrantSet.AddPermission(new UIPermission(UIPermissionClipboard.NoClipboard));
pstGrantSet.AddPermission(new UIPermission(UIPermissionWindow.AllWindows));
pstGrantSet.AddPermission(new MediaPermission(MediaPermissionImage.SafeImage));
//add the specific permissions the script will need
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, m_gmdGameMode.GameModeEnvironmentInfo.ModDirectory));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, m_gmdGameMode.GameModeEnvironmentInfo.ModCacheDirectory));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Write, m_gmdGameMode.GameModeEnvironmentInfo.InstallInfoDirectory));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, m_gmdGameMode.GameModeEnvironmentInfo.InstallInfoDirectory));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Write, Path.GetTempPath()));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, Path.GetTempPath()));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Append, Path.GetTempPath()));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.PathDiscovery, Path.GetTempPath()));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Write, m_eifEnvironmentInfo.TemporaryPath));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, m_eifEnvironmentInfo.TemporaryPath));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Append, m_eifEnvironmentInfo.TemporaryPath));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.PathDiscovery, m_eifEnvironmentInfo.TemporaryPath));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Write, m_gmdGameMode.GameModeEnvironmentInfo.InstallationPath));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, m_gmdGameMode.GameModeEnvironmentInfo.InstallationPath));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Append, m_gmdGameMode.GameModeEnvironmentInfo.InstallationPath));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.PathDiscovery, m_gmdGameMode.GameModeEnvironmentInfo.InstallationPath));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Write, m_gmdGameMode.GameModeEnvironmentInfo.OverwriteDirectory));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, m_gmdGameMode.GameModeEnvironmentInfo.OverwriteDirectory));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Append, m_gmdGameMode.GameModeEnvironmentInfo.OverwriteDirectory));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.PathDiscovery, m_gmdGameMode.GameModeEnvironmentInfo.OverwriteDirectory));
foreach (string strPath in m_gmdGameMode.WritablePaths)
{
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Write, strPath));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, strPath));
if (Directory.Exists(strPath))
{
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Append, strPath));
pstGrantSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.PathDiscovery, strPath));
}
}
Trace.Unindent();
//.........这里部分代码省略.........
示例9: GetFiles
/// <summary>
/// Gets a list of files that are in the specified directory in this archive.
/// </summary>
/// <param name="p_strDirectory">The directory in the archive whose descendents are to be returned.</param>
/// <param name="p_booRecurse">Whether to return files that are in subdirectories of the given directory.</param>
/// <returns>A list of files that are in the specified directory in this archive.</returns>
public string[] GetFiles(string p_strDirectory, bool p_booRecurse)
{
Set<string> lstFiles = new Set<string>(StringComparer.InvariantCultureIgnoreCase);
if (String.IsNullOrEmpty(p_strDirectory))
{
m_strFiles.ForEach((s) => { lstFiles.Add(String.Copy(s)); });
}
else
{
string strPrefix = p_strDirectory;
strPrefix = strPrefix.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
strPrefix = strPrefix.Trim(Path.DirectorySeparatorChar);
if (strPrefix.Length > 0)
strPrefix += Path.DirectorySeparatorChar;
Int32 intStopIndex = 0;
foreach (string strFile in m_strFiles)
{
if (strFile.StartsWith(strPrefix, StringComparison.InvariantCultureIgnoreCase))
{
if (!p_booRecurse)
{
intStopIndex = strFile.IndexOf(Path.DirectorySeparatorChar, strPrefix.Length);
if (intStopIndex > 0)
continue;
}
lstFiles.Add(String.Copy(strFile));
}
}
}
return lstFiles.ToArray();
}
示例10: UniqueWordforms
///// <summary>
///// Return true if it is necessary to reload the contents of the text into the cache
///// in order to have an up-to-date parse of the text. Assumes that ParagraphsModifiedTimestamp
///// is either not cached (and will now be loaded), or has been updated recently enough to be
///// relied upon.
///// </summary>
//bool RequiresReloadForParse
//{
// get
// {
// return ParagraphsModifiedTimestamp != LastParsedTimestamp;
// }
//}
///// <summary>
///// Return true if it is necessary to reparse this text in order to have an accurate concordance
///// of its contents. Should be kept in sync with NoteParsed.
///// </summary>
//bool RequiresParsing
//{
// get
// {
// if (ParagraphsModifiedTimestamp == LastParsedTimestamp)
// return false;
// if (LastParsedTimestamp == 0)
// return true;
// }
//}
///// <summary>
///// Note that the text has been parsed, and save whatever information is needed so we can later
///// determine whether it need be parsed again. If no dummy annotations were used, we record
///// a property on the text itself to indicate that we have a complete set of real annotations
///// for the text as of its current ParagraphsModifiedTimestamp.
///// </summary>
///// <param name="hasDummyAnnotations"></param>
//void NoteParsed(bool hasDummyAnnotations)
//{
// LastParsedTimestamp = ParagraphsModifiedTimestamp;
// ClearLastModifiedTimestamp(); // so it must be reloaded for the next test of RequiresParsing
//}
/// <summary>
/// Get list of unique wordforms in this text
/// </summary>
/// <returns>A List that contains zero, or more, integers (hvos) for the unique wordforms occurring in this text.</returns>
public int[] UniqueWordforms()
{
Set<int> wordforms = new Set<int>();
foreach (IStTxtPara para in ParagraphsOS)
{
para.CollectUniqueWordforms(wordforms);
}
return wordforms.ToArray();
// string qry = "SELECT DISTINCT wwf.id FROM WfiWordform wwf " +
// "JOIN StTxtPara_TextObjects para ON para.dst=wwf.id " +
// "JOIN StText_paragraphs text ON text.Src=? " +
// "WHERE text.dst=para.src " +
// "ORDER BY wwf.id";
// return DbOps.ReadIntsFromCommand(m_cache, qry, Hvo);
}
示例11: GetBestAlt
private int GetBestAlt(int hvo, int tag, int wsPreferred, int wsDefault, int[] wsList)
{
Set<int> wsSet = new Set<int>();
if (wsPreferred != 0)
wsSet.Add(wsPreferred);
wsSet.AddRange(wsList);
// We're not dealing with a real cache, so can't call something like this:
//ws = LangProject.InterpretWsLabel(m_caches.MainCache,
// LangProject.GetMagicWsNameFromId(ws),
// m_caches.MainCache.DefaultAnalWs,
// hvo, spec.StringFlid, null);
int wsActual = 0;
foreach (int ws1 in wsSet.ToArray())
{
ITsString tssTest = m_caches.DataAccess.get_MultiStringAlt(hvo, tag, ws1);
if (tssTest != null && tssTest.Length != 0)
{
wsActual = ws1;
break;
}
}
// Enhance JohnT: to be really picky here we should do like the real InterpretWsLabel
// and fall back to default UI language, then English.
// But we probably aren't even copying those alternatives to the sandbox cache.
if (wsActual == 0)
wsActual = wsDefault;
return wsActual;
}
示例12: TestToArray
public void TestToArray() {
var set1 = new Set<int>();
set1.Add(new [] { 1, 2, 3, 5 });
var intArray = set1.ToArray();
foreach (var i in intArray) {
Assert.True(set1.Contains(i));
}
Assert.Equals(set1.Count, intArray.GetLength(0));
}
示例13: GetColumnNames
public static string[] GetColumnNames(string path, string rootElementName, string rowElementName)
{
Console.Out.WriteLine("Scanning \"" + path + "\" for input field names...");
using (FileStream file = new FileStream(path, FileMode.Open))
{
XmlParser p = new XmlParser(file);
p.SkipToElement(rootElementName);
Set<string> columnNames = new Set<string>(false);
while (true)
{
p.MoveToElementNode(false);
string rowXML = p.OuterXML(rowElementName);
if (rowXML == null)
break;
XmlParser rowP = new XmlParser(rowXML);
rowP.MoveToElementNode(true);
while (rowP.MoveToElementNode(false) != null)
columnNames.Add(rowP.CurrentName);
}
return columnNames.ToArray();
}
}
示例14: DeleteText_BasicChart
public void DeleteText_BasicChart()
{
MakeFakeWfics(); // annotation hvos are stored in List m_hvoAnnot.
MakeFakeTemplate(); // template hvos are stored in m_cols[].
// CCA annotation hvos are stored in m_expectedCCAHvos, but should get deleted!
// CCR annotation hvos are stored in m_expectedCCRHvos, but should get deleted!
MakeBasicChart();
Set<int> hvosToDelete = new Set<int>();
using (NullProgressState state = new NullProgressState())
{
// SUT
m_stText.DeleteObjectSideEffects(hvosToDelete, state);
}
int[] hvosActual = hvosToDelete.ToArray();
// 10 = chartHvo, TextHvo, StTextHvo, 2XCCRHvo, 5XCCAHvo
Assert.AreEqual(10, hvosActual.Length, "Wrong number of hvos to delete.");
Assert.Contains(m_chart.Hvo, hvosActual, "The (empty) chart should be deleted.");
Assert.AreEqual(
(int)SIL.FieldWorks.FDO.CmObject.SpecialHVOValues.kHvoUnderlyingObjectDeleted,
m_stText.Hvo, "StText is already deleted.");
Assert.Contains(m_text.Hvo, hvosActual, "The containing Text should be deleted.");
AssertArrayContainedInArray(m_expectedCCAHvos.ToArray(), hvosActual);
AssertArrayContainedInArray(m_expectedCCRHvos.ToArray(), hvosActual);
}
示例15: DeleteText_WficsButEmptyChart
public void DeleteText_WficsButEmptyChart()
{
MakeFakeWfics(); // annotation hvos are stored in List m_hvoAnnot.
Set<int> hvosToDelete = new Set<int>();
using (NullProgressState state = new NullProgressState())
{
// SUT
m_stText.DeleteObjectSideEffects(hvosToDelete, state);
}
int[] hvosActual = hvosToDelete.ToArray();
Assert.AreEqual(3, hvosActual.Length, "Wrong number of hvos to delete.");
Assert.Contains(m_chart.Hvo, hvosActual, "The (empty) chart should be deleted.");
Assert.AreEqual(
(int)SIL.FieldWorks.FDO.CmObject.SpecialHVOValues.kHvoUnderlyingObjectDeleted,
m_stText.Hvo, "StText is already deleted.");
Assert.Contains(m_text.Hvo, hvosActual, "The containing Text should be deleted.");
}