本文整理汇总了C#中System.Collections.Generic.List.IndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.List.IndexOf方法的具体用法?C# System.Collections.Generic.List.IndexOf怎么用?C# System.Collections.Generic.List.IndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.List
的用法示例。
在下文中一共展示了System.Collections.Generic.List.IndexOf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MouseMoveSurface
public void MouseMoveSurface(MouseInfo info, ITextSurface surface)
{
Brush.Position = info.ConsoleLocation;
Brush.IsVisible = true;
if (info.LeftClicked)
{
Cell cellToMatch = new Cell();
Cell currentFillCell = new Cell();
surface.GetCell(info.ConsoleLocation.X, info.ConsoleLocation.Y).Copy(cellToMatch);
cellToMatch.Effect = surface.GetCell(info.ConsoleLocation.X, info.ConsoleLocation.Y).Effect;
currentFillCell.GlyphIndex = CharacterPickPanel.SharedInstance.SettingCharacter;
currentFillCell.Foreground = CharacterPickPanel.SharedInstance.SettingForeground;
currentFillCell.Background = CharacterPickPanel.SharedInstance.SettingBackground;
currentFillCell.SpriteEffect = CharacterPickPanel.SharedInstance.SettingMirrorEffect;
Func<Cell, bool> isTargetCell = (c) =>
{
bool effect = c.Effect == null && cellToMatch.Effect == null;
if (c.Effect != null && cellToMatch.Effect != null)
effect = c.Effect == cellToMatch.Effect;
if (c.GlyphIndex == 0 && cellToMatch.GlyphIndex == 0)
return c.Background == cellToMatch.Background;
return c.Foreground == cellToMatch.Foreground &&
c.Background == cellToMatch.Background &&
c.GlyphIndex == cellToMatch.GlyphIndex &&
c.SpriteEffect == cellToMatch.SpriteEffect &&
effect;
};
Action<Cell> fillCell = (c) =>
{
currentFillCell.Copy(c);
//console.TextSurface.SetEffect(c, _currentFillCell.Effect);
};
System.Collections.Generic.List<Cell> cells = new System.Collections.Generic.List<Cell>(surface.Cells);
Func<Cell, SadConsole.Algorithms.NodeConnections<Cell>> getConnectedCells = (c) =>
{
Algorithms.NodeConnections<Cell> connections = new Algorithms.NodeConnections<Cell>();
Point position = TextSurface.GetPointFromIndex(cells.IndexOf(c), surface.Width);
connections.West = surface.IsValidCell(position.X - 1, position.Y) ? surface.GetCell(position.X - 1, position.Y) : null;
connections.East = surface.IsValidCell(position.X + 1, position.Y) ? surface.GetCell(position.X + 1, position.Y) : null;
connections.North = surface.IsValidCell(position.X, position.Y - 1) ? surface.GetCell(position.X, position.Y - 1) : null;
connections.South = surface.IsValidCell(position.X, position.Y + 1) ? surface.GetCell(position.X, position.Y + 1) : null;
return connections;
};
if (!isTargetCell(currentFillCell))
SadConsole.Algorithms.FloodFill<Cell>(surface.GetCell(info.ConsoleLocation.X, info.ConsoleLocation.Y), isTargetCell, fillCell, getConnectedCells);
}
if (info.RightButtonDown)
{
var cell = surface.GetCell(info.ConsoleLocation.X, info.ConsoleLocation.Y);
CharacterPickPanel.SharedInstance.SettingCharacter = cell.GlyphIndex;
CharacterPickPanel.SharedInstance.SettingForeground = cell.Foreground;
CharacterPickPanel.SharedInstance.SettingBackground = cell.Background;
CharacterPickPanel.SharedInstance.SettingMirrorEffect = cell.SpriteEffect;
}
}
示例2: MathParserLogic
private int MathParserLogic(System.Collections.Generic.List<string> _tokens)
{
// CALCULATING THE EXPRESSIONS INSIDE THE BRACKETS
// IF NEEDED, EXECUTE A FUNCTION
while (_tokens.IndexOf("(") != -1)
{
// getting data between "(", ")"
int open = _tokens.LastIndexOf("(");
int close = _tokens.IndexOf(")", open); // in case open is -1, i.e. no "(" // , open == 0 ? 0 : open - 1
if (open >= close)
{
// if there is no closing bracket, throw a new exception
throw new ArithmeticException("No closing bracket/parenthesis! tkn: " + open);
}
var roughExpr = new System.Collections.Generic.List<string>();
for (int i = open + 1; i < close; i++)
{
roughExpr.Add(_tokens[i]);
}
int result; // the temporary result is stored here
string functioName = _tokens[open == 0 ? 0 : open - 1];
var _args = new int[0];
if (this.LocalFunctions.Keys.Contains(functioName))
{
if (roughExpr.Contains(","))
{
// converting all arguments into a int array
for (int i = 0; i < roughExpr.Count; i++)
{
int firstCommaOrEndOfExpression = roughExpr.IndexOf(",", i) != -1
? roughExpr.IndexOf(",", i)
: roughExpr.Count;
var defaultExpr = new System.Collections.Generic.List<string>();
while (i < firstCommaOrEndOfExpression)
{
defaultExpr.Add(roughExpr[i]);
i++;
}
// changing the size of the array of arguments
Array.Resize(ref _args, _args.Length + 1);
if (defaultExpr.Count == 0)
{
_args[_args.Length - 1] = 0;
}
else
{
_args[_args.Length - 1] = this.BasicArithmeticalExpression(defaultExpr);
}
}
// finnaly, passing the arguments to the given function
result = int.Parse(
this.LocalFunctions[functioName](_args).ToString(this.CULTURE_INFO),
this.CULTURE_INFO);
}
else
{
// but if we only have one argument, then we pass it directly to the function
result =
int.Parse(
this.LocalFunctions[functioName](new[] { this.BasicArithmeticalExpression(roughExpr) })
.ToString(this.CULTURE_INFO),
this.CULTURE_INFO);
}
}
else
{
// if no function is need to execute following expression, pass it
// to the "BasicArithmeticalExpression" method.
result = this.BasicArithmeticalExpression(roughExpr);
}
// when all the calculations have been done
// we replace the "opening bracket with the result"
// and removing the rest.
_tokens[open] = result.ToString(this.CULTURE_INFO);
_tokens.RemoveRange(open + 1, close - open);
if (this.LocalFunctions.Keys.Contains(functioName))
{
// if we also executed a function, removing
// the function name as well.
_tokens.RemoveAt(open - 1);
}
}
// at this point, we should have replaced all brackets
// with the appropriate values, so we can simply
// calculate the expression. it's not so complex
// any more!
return this.BasicArithmeticalExpression(_tokens);
}
示例3: NetSerial
internal void NetSerial()
{
try
{
searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT Name,NetConnectionID,Manufacturer,PNPDeviceID,MACAddress FROM Win32_NetworkAdapter");
ManagementObjectCollection net = searcher.Get();
//PHYISICALADAPTER NOT AVAILABLE IN XP
//string netCompStr = "xxx"; //to ensure no matchif not assigned
//var count = net.Cast<ManagementObject>().Where(s => s.GetPropertyValue("NetConnectionID") != null).Count(c => String.Compare((string)c.GetPropertyValue("NetConnectionID"), 0, "Local Area Connection", 0, 20) == 0); //prior to Windows 8
//if (count > 0)
// netCompStr = net.Cast<ManagementObject>().Where(s => s.GetPropertyValue("NetConnectionID") != null).Where(c => String.Compare((string)c.GetPropertyValue("NetConnectionID"), 0, "Local Area Connection", 0, 20) == 0).Min(s => (string)s.GetPropertyValue("NetConnectionID")); //should result in lowest numbered local area connection
//else if (count == 0)
//{
// var cnt = net.Cast<ManagementObject>().Where(s => s.GetPropertyValue("NetConnectionID") != null).Count(c => String.Compare((string)c.GetPropertyValue("NetConnectionID"), 0, "Ethernet", 0, 8) == 0); //Windows 8
// if (cnt > 0)
// netCompStr = net.Cast<ManagementObject>().Where(s => s.GetPropertyValue("NetConnectionID") != null).Where(c => String.Compare((string)c.GetPropertyValue("NetConnectionID"), 0, "Ethernet", 0, 8) == 0).Min(s => (string)s.GetPropertyValue("NetConnectionID")); //should result in lowest numbered local area connection
// //may need a wireless here in future for tablets
//}
//foreach (ManagementObject queryObj in net)
//{
// if ((string)queryObj.GetPropertyValue("NetConnectionID") == netCompStr)
// {
// sysData.compLAC_Name = (string)queryObj.GetPropertyValue("Name");
// sysData.compLAC_Mac = (string)queryObj.GetPropertyValue("MACAddress");
// break;
// }
//
//}
System.Collections.Generic.List<string> macAddrs = new System.Collections.Generic.List<string>();
System.Collections.Generic.List<string> names = new System.Collections.Generic.List<string>();
foreach (ManagementObject queryObj in net)
{
if (queryObj.GetPropertyValue("MACAddress") == null)
continue;
if (queryObj.GetPropertyValue("Manufacturer") == null)
continue;
else
{
if (queryObj.GetPropertyValue("Manufacturer").ToString().ToLower() == "microsoft")
continue;
}
Log.WritW("WMINetAdapter: MAC: " + queryObj.GetPropertyValue("MACAddress"));
string netConn = (string)queryObj.GetPropertyValue("NetConnectionID");
if (netConn != null && netConn.IndexOf("Wireless",StringComparison.CurrentCultureIgnoreCase) != -1)
continue;
string name = (string)queryObj.GetPropertyValue("Name");
if (name == null)
continue;
name = name.ToLower();
if (name.Contains("bluetooth") || name.Contains("wireless") || name.Contains("wifi") || name.Contains("mobile") || name.Contains("wlan") || name.Contains("802.11"))
continue;
if (queryObj.GetPropertyValue("PNPDeviceID").ToString().Contains("ROOT"))
continue;
macAddrs.Add(queryObj.GetPropertyValue("MACAddress").ToString());
names.Add(queryObj.GetPropertyValue("Name").ToString());
}
Log.WriteStr("MAC Address count : " + macAddrs.Count.ToString());
macAddress = macAddrs.Min();
string str = "";
if (macAddrs.Count > 1)
str = macAddrs.Count.ToString();
if (macAddrs.Count > 0)
{
sysData.compLAC_Name = names[macAddrs.IndexOf(macAddress)] + str;
sysData.compLAC_Mac = macAddress;
}
Log.WritW("NetAdapter Final: serial: " + sysData.compLAC_Mac + " NetAdapterName: " + sysData.compLAC_Name);
}
catch (ManagementException e)
{
MessageBox.Show("An Error occurred while querying Net Adapter Info WMI data: " + e.Message, "Tax-Aide Inventory Data Collection");
Log.WritW("An Error occurred while querying Network WMI data: " + e.Message);
Environment.Exit(0);
}
}