本文整理汇总了C#中List.Add方法的典型用法代码示例。如果您正苦于以下问题:C# List.Add方法的具体用法?C# List.Add怎么用?C# List.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDatabases
private static DataTable GetDatabases(IMyMetaTestContext criteria, IMyMetaPlugin plugin)
{
if (_databases == null)
{
_databases = plugin.Databases;
if (criteria.DefaultDatabaseOnly)
{
List<DataRow> rowsToDelete = new List<DataRow>();
string defaultDb = plugin.DefaultDatabase;
if (!string.IsNullOrEmpty(defaultDb))
{
defaultDb = defaultDb.Trim();
foreach (DataRow dbRow in _databases.Rows)
{
string dbname = dbRow["CATALOG_NAME"].ToString();
if (dbname != defaultDb) rowsToDelete.Add(dbRow);
}
}
if (rowsToDelete.Count != (_databases.Rows.Count - 1))
{
rowsToDelete.Clear();
for (int i = 1; i < _databases.Rows.Count; i++) rowsToDelete.Add(_databases.Rows[i]);
}
foreach (DataRow dbRow in rowsToDelete) _databases.Rows.Remove(dbRow);
}
}
return _databases;
}
示例2: Split
public static string[] Split(string str, char[] separators, int maxComponents, StringSplitOptions options)
{
ContractUtils.RequiresNotNull(str, "str");
#if SILVERLIGHT || WP75
if (separators == null) return SplitOnWhiteSpace(str, maxComponents, options);
bool keep_empty = (options & StringSplitOptions.RemoveEmptyEntries) != StringSplitOptions.RemoveEmptyEntries;
List<string> result = new List<string>(maxComponents == Int32.MaxValue ? 1 : maxComponents + 1);
int i = 0;
int next;
while (maxComponents > 1 && i < str.Length && (next = str.IndexOfAny(separators, i)) != -1) {
if (next > i || keep_empty) {
result.Add(str.Substring(i, next - i));
maxComponents--;
}
i = next + 1;
}
if (i < str.Length || keep_empty) {
result.Add(str.Substring(i));
}
return result.ToArray();
#else
return str.Split(separators, maxComponents, options);
#endif
}
示例3: SetupAutoCADIOContainer
/// <summary>
/// Does setup of AutoCAD IO.
/// This method will need to be invoked once before any other methods of this
/// utility class can be invoked.
/// </summary>
/// <param name="autocadioclientid">AutoCAD IO Client ID - can be obtained from developer.autodesk.com</param>
/// <param name="autocadioclientsecret">AutoCAD IO Client Secret - can be obtained from developer.autodesk.com</param>
public static void SetupAutoCADIOContainer(String autocadioclientid, String autocadioclientsecret)
{
try
{
String clientId = autocadioclientid;
String clientSecret = autocadioclientsecret;
Uri uri = new Uri("https://developer.api.autodesk.com/autocad.io/us-east/v2/");
container = new AIO.Operations.Container(uri);
container.Format.UseJson();
using (var client = new HttpClient())
{
var values = new List<KeyValuePair<string, string>>();
values.Add(new KeyValuePair<string, string>("client_id", clientId));
values.Add(new KeyValuePair<string, string>("client_secret", clientSecret));
values.Add(new KeyValuePair<string, string>("grant_type", "client_credentials"));
var requestContent = new FormUrlEncodedContent(values);
var response = client.PostAsync("https://developer.api.autodesk.com/authentication/v1/authenticate", requestContent).Result;
var responseContent = response.Content.ReadAsStringAsync().Result;
var resValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(responseContent);
_accessToken = resValues["token_type"] + " " + resValues["access_token"];
if (!string.IsNullOrEmpty(_accessToken))
{
container.SendingRequest2 += (sender, e) => e.RequestMessage.SetHeader("Authorization", _accessToken);
}
}
}
catch (System.Exception ex)
{
Console.WriteLine(String.Format("Error while connecting to https://developer.api.autodesk.com/autocad.io/v2/", ex.Message));
container = null;
throw;
}
}
示例4: LoadState
/// <summary>
/// Füllt die Seite mit Inhalt auf, der bei der Navigation übergeben wird. Gespeicherte Zustände werden ebenfalls
/// bereitgestellt, wenn eine Seite aus einer vorherigen Sitzung neu erstellt wird.
/// </summary>
/// <param name="navigationParameter">Der Parameterwert, der an
/// <see cref="Frame.Navigate(Type, Object)"/> übergeben wurde, als diese Seite ursprünglich angefordert wurde.
/// </param>
/// <param name="pageState">Ein Wörterbuch des Zustands, der von dieser Seite während einer früheren Sitzung
/// beibehalten wurde. Beim ersten Aufrufen einer Seite ist dieser Wert NULL.</param>
protected override async void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
// Zulassen, dass das anfänglich anzuzeigende Element vom gespeicherten Seitenzustand überschrieben wird
if (pageState != null && pageState.ContainsKey("SelectedItem"))
{
navigationParameter = pageState["SelectedItem"];
}
ChampionsViewModel championsViewModel = (ChampionsViewModel)App.Current.Resources["championsViewModel"];
if (championsViewModel != null)
{
if (!championsViewModel.Loaded) await championsViewModel.LoadDataAsync();
this.DefaultViewModel["Items"] = championsViewModel.Champions.OrderBy(c => c.displayName).ToList();
Champion champion = championsViewModel.Champions.First<Champion>(c => c.id == (int)navigationParameter);
this.flipView.SelectedItem = champion;
List<ChampionItemDetailPageView> views = new List<ChampionItemDetailPageView>();
ChampionItemDetailPageView lore = new ChampionItemDetailPageView("Lore");
ChampionItemDetailPageView overview = new ChampionItemDetailPageView("Overview");
ChampionItemDetailPageView tips = new ChampionItemDetailPageView("Tips");
views.Add(overview);
views.Add(lore);
views.Add(tips);
this.DefaultViewModel["Views"] = views;
}
}
示例5: CreateModel
private void CreateModel()
{
int steps = (int)(1 / 0.05);
double side = 100;
// Generate the vertices
Points = new List<Point3D>();
for (int i = 0; i <= steps; i++)
{
double t = (double)i / steps;
double x = side * Math.Cos(t * 2 * Math.PI);
double y = side * Math.Sin(t * 2 * Math.PI);
Points.Add(new Point3D(x, y, -side));
}
Points.Add(new Point3D(0, 0, -side));
Points.Add(new Point3D(0, 0, side));
// Generate the faces
Faces = new List<int[]>();
for (int i = 0; i < steps; i++)
{
int[] face = { i, i + 1, Points.Count-1};
int[] sectorBottom = { i, i+1, Points.Count - 2};
Faces.Add(face);
Faces.Add(sectorBottom);
}
FacePoints = 3;
}
示例6: CategoryAll
/// <summary>
/// ��ѯʵ��
/// </summary>
/// <param name="id">ModelId ���</param>
/// <returns>ModelCategory</returns>
public IList<ModelCategory> CategoryAll(out string resultMsg, Int32 ParentCateg = 0,string IsNav = null)
{
resultMsg = string.Empty;
IList<ModelCategory> list = new List<ModelCategory>();
try
{
//�洢��������
string sql = "usp_category_select_all";
//�������
IList<DBParameter> parm = new List<DBParameter>();
parm.Add(new DBParameter() { ParameterName = "@ParentCateg", ParameterValue = ParentCateg, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.Int32 });
parm.Add(new DBParameter() { ParameterName = "@IsNav", ParameterValue = IsNav, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.String });
//��ѯִ��
using (IDataReader dr = DBHelper.ExecuteReader(sql, true, parm))
{
list = GetModel(dr);
}
}
catch (Exception ex)
{
resultMsg = string.Format("{0} {1}", BaseDict.ErrorPrefix, ex.ToString());
}
return list;
}
示例7: getWeaknesses
public override List<Type> getWeaknesses()
{
List<Type> weak = new List<Type>();
weak.Add(new Electric());
weak.Add(new Grass());
return weak;
}
示例8: Main
static void Main(string[] args)
{
List<int> list = new List<int>
{
3,2,
}; // 3, 2
list.Add(5); // 3, 2, 5
list.Add(6); // 3, 2, 5, 6
list.Remove(5); // 3, 2, 6
Queue<int> queue = new Queue<int>();
queue.Enqueue(3);// 3
queue.Enqueue(8);// 3, 8
queue.Dequeue(); // 8
Stack<int> stack = new Stack<int>();
stack.Push(2); // 2
stack.Push(7); // 7, 2
stack.Push(8); // 8, 7, 2
stack.Pop(); // 7, 2
foreach (var i in stack)
{
Console.WriteLine(i);
}
LinkedList<int> linkedList = new LinkedList<int>();
linkedList.AddFirst(9); // 9
linkedList.AddAfter(linkedList.Find(9), 5); // 9, 5
linkedList.Remove(9); // 5
Console.Read();
}
示例9: GetMediaType
public IMediaType GetMediaType(string acceptHeader)
{
if (string.IsNullOrEmpty(acceptHeader)) return mediaTypes.Default;
var types = acceptHeader.Split(',');
var acceptedMediaType = new List<QualifiedMediaType>();
foreach (var type in types)
{
var parsedFormat = ParseFormat(type);
if (IsDefaultFormat(parsedFormat.Format))
{
acceptedMediaType.Add(new QualifiedMediaType(mediaTypes.Default, parsedFormat.Qualifier));
}
else
{
var mediaType = mediaTypes.Find(parsedFormat.Format);
if (mediaType != null) acceptedMediaType.Add(new QualifiedMediaType(mediaType, parsedFormat.Qualifier));
}
}
if (acceptedMediaType.Count == 0) throw new AcceptHeaderNotSupportedException();
return MostQualifiedMediaType(acceptedMediaType);
}
示例10: GetLengthBytes
private byte[] GetLengthBytes()
{
var payloadLengthBytes = new List<byte>(9);
if (PayloadLength > ushort.MaxValue)
{
payloadLengthBytes.Add(127);
byte[] lengthBytes = BitConverter.GetBytes(PayloadLength);
if (BitConverter.IsLittleEndian)
Array.Reverse(lengthBytes);
payloadLengthBytes.AddRange(lengthBytes);
}
else if (PayloadLength > 125)
{
payloadLengthBytes.Add(126);
byte[] lengthBytes = BitConverter.GetBytes((UInt16) PayloadLength);
if (BitConverter.IsLittleEndian)
Array.Reverse(lengthBytes);
payloadLengthBytes.AddRange(lengthBytes);
}
else
{
payloadLengthBytes.Add((byte) PayloadLength);
}
payloadLengthBytes[0] += (byte) (IsMasked ? 128 : 0);
return payloadLengthBytes.ToArray();
}
示例11: BookCollection
public BookCollection()
{
books = new List<Book>();
books.Add(new Book { Id = 1, Name = "Война и мир", Author = "Л. Толстой", Price = 220 });
books.Add(new Book { Id = 2, Name = "Отцы и дети", Author = "И. Тургенев", Price = 180 });
books.Add(new Book { Id = 3, Name = "Чайка", Author = "А. Чехов", Price = 150 });
}
示例12: CreateInsertParameters
public override List<SqlParameter> CreateInsertParameters(IModel obj, ref SqlParameter returnValue)
{
FinanceBusinessInvoice inv_financebusinessinvoice_ref = (FinanceBusinessInvoice)obj;
List<SqlParameter> paras = new List<SqlParameter>();
returnValue.Direction = ParameterDirection.Output;
returnValue.SqlDbType = SqlDbType.Int;
returnValue.ParameterName = "@RefId";
returnValue.Size = 4;
paras.Add(returnValue);
SqlParameter businessinvoiceidpara = new SqlParameter("@BusinessInvoiceId", SqlDbType.Int, 4);
businessinvoiceidpara.Value = inv_financebusinessinvoice_ref.BusinessInvoiceId;
paras.Add(businessinvoiceidpara);
SqlParameter financeinvoiceidpara = new SqlParameter("@FinanceInvoiceId", SqlDbType.Int, 4);
financeinvoiceidpara.Value = inv_financebusinessinvoice_ref.FinanceInvoiceId;
paras.Add(financeinvoiceidpara);
SqlParameter balapara = new SqlParameter("@Bala", SqlDbType.Decimal, 9);
balapara.Value = inv_financebusinessinvoice_ref.Bala;
paras.Add(balapara);
return paras;
}
示例13: Visit
public override Template Visit(GlobalBlock block)
{
Template template = new Template("<list; separator=\"\n\">");
List<Template> list = new List<Template>();
bool last = false;
AstNode last_node = null;
foreach (var node in block.List)
{
bool current = node is FuncDef || node is Class || node is Enum || node is Import || node is GlobalUsing || node is Namespace;
if ((last || current) && !(last_node is Import && node is Import))
{
Template tp = new Template("\n<node>");
tp.Add("node", node.Accept(this));
list.Add(tp);
}
else
{
list.Add(node.Accept(this));
}
last = current;
last_node = node;
}
template.Add("list", list);
return template;
}
示例14: Process
public dynamic Process(NancyModule nancyModule, AuthenticateCallbackData model)
{
Response response = nancyModule.Response.AsRedirect("~/");
if (nancyModule.IsAuthenticated())
{
response = nancyModule.Response.AsRedirect("~/account/#identityProviders");
}
if (model.Exception != null)
{
nancyModule.Request.AddAlertMessage("error", model.Exception.Message);
}
else
{
UserInformation information = model.AuthenticatedClient.UserInformation;
var claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.NameIdentifier, information.Id));
claims.Add(new Claim(ClaimTypes.AuthenticationMethod, model.AuthenticatedClient.ProviderName));
if (!String.IsNullOrEmpty(information.UserName))
{
claims.Add(new Claim(ClaimTypes.Name, information.UserName));
}
if (!String.IsNullOrEmpty(information.Email))
{
claims.Add(new Claim(ClaimTypes.Email, information.Email));
}
nancyModule.SignIn(claims);
}
return response;
}
示例15: values
protected override List<Value> values(Vessel vessel, GameEvent events)
{
List<Value> values = new List<Value> ();
int count = 0;
if (vessel != null) {
foreach (Part p in vessel.Parts) {
if (p.partInfo.name.Equals (partName)) {
++count;
}
}
}
if(maxPartCount == -1) {
if (vessel == null) {
values.Add (new Value ("Part", partCount + "x " + partName));
} else {
values.Add (new Value ("Part", partCount + "x " + partName, "" + count, count >= partCount));
}
} else {
if (vessel == null) {
values.Add (new Value ("max part", maxPartCount + "x " + partName));
} else {
values.Add (new Value ("max part", maxPartCount + "x " + partName, "" + count, count <= maxPartCount));
}
}
return values;
}