当前位置: 首页>>代码示例>>C#>>正文


C# List.ConvertAll方法代码示例

本文整理汇总了C#中List.ConvertAll方法的典型用法代码示例。如果您正苦于以下问题:C# List.ConvertAll方法的具体用法?C# List.ConvertAll怎么用?C# List.ConvertAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在List的用法示例。


在下文中一共展示了List.ConvertAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            List<string> words = new List<string>(); // New string-typed list
            words.Add("melon");
            words.Add("avocado");
            words.AddRange(new[] { "banana", "plum" });
            words.Insert(0, "lemon"); // Insert at start
            words.InsertRange(0, new[] { "peach", "nashi" }); // Insert at start
            words.Remove("melon");
            words.RemoveAt(3); // Remove the 4th element
            words.RemoveRange(0, 2); // Remove first 2 elements
            words.RemoveAll(s => s.StartsWith("n"));// Remove all strings starting in 'n'
            Console.WriteLine(words[0]); // first word
            Console.WriteLine(words[words.Count - 1]); // last word
            foreach (string s in words) Console.WriteLine(s); // all words
            List<string> subset = words.GetRange(1, 2); // 2nd->3rd words
            string[] wordsArray = words.ToArray(); // Creates a new typed array
            string[] existing = new string[1000];// Copy first two elements to the end of an existing array
            words.CopyTo(0, existing, 998, 2);
            List<string> upperCastWords = words.ConvertAll(s => s.ToUpper());
            List<int> lengths = words.ConvertAll(s => s.Length);

            ArrayList al = new ArrayList();
            al.Add("hello");
            string first = (string)al[0];
            string[] strArr = (string[])al.ToArray(typeof(string));
            List<string> list = al.Cast<string>().ToList();
        }
开发者ID:PhilTheAir,项目名称:CSharp,代码行数:28,代码来源:ListArrayList.cs

示例2: ExtendedStatistics

 public ExtendedStatistics(List<double> values)
     : base(values)
 {
     mad = computeMad(values.ConvertAll<double>(p => p));
     iqr = computeIQR(values.ConvertAll<double>(p => p));
     entropy = computeEntropy(values.ConvertAll<double>(p => p));
     maxIndex = computeMaxIndex(values.ConvertAll<double>(p => p));
     autocorr = computeAutocorr(values.ConvertAll<double>(p => p));
 }
开发者ID:catInet,项目名称:tcpServer,代码行数:9,代码来源:ExtendedStatistics.cs

示例3: Domain

        /**
         * Constructor taking the outside-the-scope value and a list of integer values, to
         * make both the initial and current possible variable values. The outside-the-scope value
         * must not belong to this list, or an ArgumentException is raised.
         */
        public Domain( List< int > domain, int outsideScope )
            : this(outsideScope)
        {
            if( domain.Contains( outsideScope ) )
            throw new ArgumentException("The outside-scope number must not be in domain", "outsideScope");

              CurrentDomain = domain.ConvertAll( v => v );
              InitialDomain = domain.ConvertAll( v => v );
        }
开发者ID:richoux,项目名称:GHOST_C_sharp,代码行数:14,代码来源:Domain.cs

示例4: _3DStatistic

 public _3DStatistic(List<double> x, List<double> y, List<double> z)
 {
     xStat = new ExtendedStatistics(x);
     yStat = new ExtendedStatistics(y);
     zStat = new ExtendedStatistics(z);
     xy_corr = computeCorrelation(x.ConvertAll<double>(p => p), y.ConvertAll<double>(p => p));
     xz_corr = computeCorrelation(x.ConvertAll<double>(p => p), z.ConvertAll<double>(p => p));
     yz_corr = computeCorrelation(y.ConvertAll<double>(p => p), z.ConvertAll<double>(p => p));
     sma = computeSMA(x.ConvertAll<double>(p => p), y.ConvertAll<double>(p => p), z.ConvertAll<double>(p => p));
     energy = computeEnergy(x.ConvertAll<double>(p => p), y.ConvertAll<double>(p => p), z.ConvertAll<double>(p => p));
 }
开发者ID:catInet,项目名称:tcpServer,代码行数:11,代码来源:_3DStatistic.cs

示例5: OutroAnimation

    IEnumerator OutroAnimation()
    {
        yield return new WaitForSeconds(1.5f);
        List<Component> components = new List<Component>(coinSpawners[currMargin].GetComponentsInChildren(typeof(Transform)));
        List<Transform> transforms = components.ConvertAll(c => (Transform)c);

        transforms.Remove(coinSpawners[currMargin].transform);
        transforms.Sort(
            delegate (Transform t1, Transform t2)
            {
                return (t1.transform.localPosition.y.CompareTo(t2.transform.localPosition.y));
            }
        );
        for (int j = transforms.Count - 1; j > -1; j--) {
            //TODO change when changing margin scripts
            if(StatePinball.Instance.ID > 2)
            {
                transforms[j].gameObject.GetComponent<CoinLoader>().strenghtXComponent = 0;
                transforms[j].gameObject.GetComponent<CoinLoader>().strenghtYComponent = 1.5f;
            }
            transforms[j].gameObject.GetComponent<CoinLoader>().ChargeIntoCannon();
            yield return new WaitForSeconds(0.2f);
        }
        yield return new WaitForSeconds(waitTimeAfterLastCoin);
        ActivateMarginSlinding();
        //StateInitializePinball.Instance.MarginDisappear();
    }
开发者ID:PaulElmo,项目名称:Listen_In-Backup-,代码行数:27,代码来源:ChallengeAnimator.cs

示例6: ReviewListMapper

        public ReviewListMapper(IAmazonRequest amazonRequest)
        {
            this.amazonRequest = amazonRequest;
            errors = new List<KeyValuePair<string, string>>();

            try
            {
                var reviewMapper = new ReviewMapper(amazonRequest.AccessKeyId, amazonRequest.AssociateTag, amazonRequest.SecretAccessKey, amazonRequest.CustomerId);

                reviews = reviewMapper.GetReviews();

                foreach (var error in reviewMapper.GetErrors())
                {
                    errors.Add(error);
                }

                var productMapper = new ProductMapper(amazonRequest.AccessKeyId, amazonRequest.AssociateTag, amazonRequest.SecretAccessKey);

                products = productMapper.GetProducts(reviews.ConvertAll(review => review.ASIN));

                foreach (var error in productMapper.GetErrors())
                {
                    errors.Add(error);
                }
            }
            catch(Exception ex)
            {
                errors.Add(new KeyValuePair<string, string>("ServiceError", ex.Message));
            }
        }
开发者ID:AdamDotCom,项目名称:adamdotcom-amazon,代码行数:30,代码来源:ReviewListMapper.cs

示例7: GetPermissionsFromNamesByValidating

        /// <summary>
        /// Gets all permissions by names.
        /// Throws <see cref="AbpValidationException"/> if can not find any of the permission names.
        /// </summary>
        public static IEnumerable<Permission> GetPermissionsFromNamesByValidating(this IPermissionManager permissionManager, IEnumerable<string> permissionNames)
        {
            var permissions = new List<Permission>();
            var undefinedPermissionNames = new List<string>();

            foreach (var permissionName in permissionNames)
            {
                var permission = permissionManager.GetPermissionOrNull(permissionName);
                if (permission == null)
                {
                    undefinedPermissionNames.Add(permissionName);
                }

                permissions.Add(permission);
            }

            if (undefinedPermissionNames.Count > 0)
            {
                throw new AbpValidationException(string.Format("There are {0} undefined permission names.", undefinedPermissionNames.Count))
                      {
                          ValidationErrors = undefinedPermissionNames.ConvertAll(permissionName => new ValidationResult("Undefined permission: " + permissionName))
                      };
            }

            return permissions;
        }
开发者ID:Zbun,项目名称:Gld.Activity.Project,代码行数:30,代码来源:PermissionManagerExtensions.cs

示例8: GetResultsFrom

		protected override CompilerResults GetResultsFrom(List<SourceFile> files)
		{
			string pdbFileName = parameters.OutputAssembly.Substring(0, parameters.OutputAssembly.Length - 3) + "pdb";
			fileSystem.Delete(parameters.OutputAssembly);
			fileSystem.Delete(pdbFileName);

			if (options.KeepTemporarySourceFiles)
			{
				string[] sourceFiles = files.ConvertAll<string>(SourceFileToFileName).ToArray();

				return codeProvider.CompileAssemblyFromFile(parameters, sourceFiles);
			}
			string[] sources = files.ConvertAll<string>(SourceFileToSource).ToArray();

			return codeProvider.CompileAssemblyFromSource(parameters, sources);
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:16,代码来源:OfflineCompiler.cs

示例9: ReadMatrix

    public static ExpressionMatrix ReadMatrix(this TCGATechnologyType ttt, TCGADataType tdt, List<BarInfo> bis, List<string> genes)
    {
      double?[,] data = new double?[genes.Count, bis.Count];
      for (int i = 0; i < bis.Count; i++)
      {
        var reader = ttt.GetTechnology().GetReader();
        var fn = tdt == TCGADataType.Count ? ttt.GetTechnology().GetCountFilename(bis[i].FileName) : bis[i].FileName;
        var dd = reader.ReadFromFile(fn).Values.ToDictionary(m => m.Name, m => m.Value);
        for (int j = 0; j < genes.Count; j++)
        {
          if (dd.ContainsKey(genes[j]))
          {
            data[j, i] = dd[genes[j]];
          }
          else
          {
            data[j, i] = null;
          }
        }
      }

      ExpressionMatrix result = new ExpressionMatrix();
      result.Values = data;
      result.Rownames = genes.ToArray();
      result.Colnames = bis.ConvertAll(m => m.BarCode).ToArray();
      return result;
    }
开发者ID:shengqh,项目名称:CQS.Core,代码行数:27,代码来源:TCGAReader.cs

示例10: GetTemplates

 public IEnumerable<string> GetTemplates(string root)
 {
     var result = new List<string>();
     IntPtr ppHier;
     uint pitemid;
     IVsMultiItemSelect ppMIS;
     IntPtr ppSC;
     object directory = "";
     if (ErrorHandler.Succeeded(GlobalServices.SelectionTracker.GetCurrentSelection(out ppHier, out pitemid, out ppMIS, out ppSC)))
     {
         try
         {
             IVsHierarchy hier = (IVsHierarchy)Marshal.GetObjectForIUnknown(ppHier);
             if (ErrorHandler.Succeeded(hier.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectDir, out directory)))
                 if (project_directory == (string)directory)
                 {
                     result.AddRange(Directory.EnumerateFiles(directory + root, "*.django", SearchOption.AllDirectories));
                     result.AddRange(Directory.EnumerateFiles(directory + root, "*.htm", SearchOption.AllDirectories));
                     result.AddRange(Directory.EnumerateFiles(directory + root, "*.html", SearchOption.AllDirectories));
                 }
         }
         finally
         {
             Marshal.Release(ppHier);
             if (!ppSC.Equals(IntPtr.Zero))
                 Marshal.Release(ppSC);
         }
     }
     return result.ConvertAll(file => file.Substring((directory + root).Length + 1));
 }
开发者ID:klewin,项目名称:NDjango,代码行数:30,代码来源:TemplateDirectory.cs

示例11: CreateFriendrequest

 public void CreateFriendrequest(List<FriendBM> frndbm)
 {
     ProWorldzContext context = new ProWorldzContext();
     List<Friend> friends = frndbm.ConvertAll<Friend>(new Converter<FriendBM, Friend>(ConvertToDM));
     context.Friend.AddRange(friends);
     context.SaveChanges();
 }
开发者ID:Vasu1990,项目名称:ProWorld,代码行数:7,代码来源:FriendBL.cs

示例12: UpdateDependencies

 internal void UpdateDependencies(List<ShadowFileNode> dependencies)
 {
     if (dependencies.Count == 0)
         buildItem.RemoveMetadata(Constants.DependsOn);
     else
         buildItem.SetMetadata(Constants.DependsOn, dependencies.ConvertAll(elem => elem.buildItem.ToString()).Aggregate("", (a, item) => a + ',' + item).Substring(1));
 }
开发者ID:Hill30,项目名称:F--Project-Extender,代码行数:7,代码来源:ShadowFileNode.cs

示例13: ProcessJavascript

		private void ProcessJavascript(List<LineOfJavascript> lines)
		{
			List<LineOfJavascript> nonAspRelatedLines = new List<LineOfJavascript>();
			foreach (var line in lines)
			{
				if (line.Namespace.IsAspControlNamespace)
				{
					line.Namespace.Lines.Add(line);
				}
				else if (line.Namespace.ParentAspControlNamespace != null)
				{
					line.Namespace.ParentAspControlNamespace.Lines.Add(line);
				}
				else
				{
					nonAspRelatedLines.Add(line);
				}
			}

			bool isDebug = inputFile.Name.EndsWith(".debug.js");
			foreach (var file in outputDirectory.GetFiles(isDebug ? "*.debug.js" : "*.js"))
			{
				file.Delete();
			}
			foreach (var ns in Namespace.Namespaces)
			{
				if (ns.Lines.Count > 0)
				{

					File.WriteAllLines(Path.Combine(outputDirectory.FullName, ns.Name + (isDebug ? ".debug" : "" ) + ".js"), ns.Lines.ConvertAll(l => l.Text).ToArray());
				}
			}

			File.WriteAllLines(Path.Combine(outputDirectory.FullName, inputFile.Name), nonAspRelatedLines.ConvertAll(l => l.Text).ToArray());
		}
开发者ID:davelondon,项目名称:dontstayin,代码行数:35,代码来源:Splitter.cs

示例14: ProductListMapper

        public ProductListMapper(IAmazonRequest amazonRequest)
        {
            this.amazonRequest = amazonRequest;
            errors = new List<KeyValuePair<string, string>>();

            try
            {
                var listMapper = new ListMapper(amazonRequest.AccessKeyId, amazonRequest.AssociateTag, amazonRequest.SecretAccessKey, amazonRequest.ListId);

                listItems = listMapper.GetList();

                foreach (var error in listMapper.GetErrors())
                {
                    errors.Add(error);
                }

                var productMapper = new ProductMapper(amazonRequest.AccessKeyId, amazonRequest.AssociateTag, amazonRequest.SecretAccessKey);

                products = productMapper.GetProducts(listItems.ConvertAll(listItem => listItem.ASIN));

                foreach (var error in productMapper.GetErrors())
                {
                    errors.Add(error);
                }
            }
            catch(Exception ex)
            {
                errors.Add(new KeyValuePair<string, string>("ServiceError", ex.Message));
            }
        }
开发者ID:AdamDotCom,项目名称:adamdotcom-amazon,代码行数:30,代码来源:ProductListMapper.cs

示例15: FormConferention

 public FormConferention(string _roomJid, string _roomName, bool _savingHistory, bool _persistRoom, string _roomDesc = "", List<string> users = null )
 {
     InitializeComponent();
     roomJid = new Jid(_roomJid);
     roomName = _roomName;
     this.Text = _roomName;
     roomDesc = _roomDesc;
     mainJid = Settings.jid;
     nickname = Settings.nickname;
     xmpp = Settings.xmpp;
     muc = new MucManager(xmpp);
     savingHistory = _savingHistory ? "1" : "0";
     persistRoom = _persistRoom ? "1" : "0";
     //muc.AcceptDefaultConfiguration(roomJid, new IqCB(OnGetFieldsResult));
     muc.CreateReservedRoom(roomJid);
     muc.GrantOwnershipPrivileges(roomJid, new Jid(mainJid));
     muc.JoinRoom(roomJid, nickname);
     initMucConfig();
     xmpp.MesagageGrabber.Add(roomJid, new BareJidComparer(), new MessageCB(MessageCallback), null);
     xmpp.PresenceGrabber.Add(roomJid, new BareJidComparer(), new PresenceCB(PresenceCallback), null);
     muc.Invite(users.ConvertAll<Jid>(
         delegate(string jid)
         {
             return new Jid(jid);
         }
     ).ToArray(), roomJid, "Вы приглашены в конференцию Конф.");
 }
开发者ID:Khelek,项目名称:XMPP,代码行数:27,代码来源:FormConferention.cs


注:本文中的List.ConvertAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。