當前位置: 首頁>>代碼示例>>C#>>正文


C# Random.PadLeft方法代碼示例

本文整理匯總了C#中System.Random.PadLeft方法的典型用法代碼示例。如果您正苦於以下問題:C# Random.PadLeft方法的具體用法?C# Random.PadLeft怎麽用?C# Random.PadLeft使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Random的用法示例。


在下文中一共展示了Random.PadLeft方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateCode

 private string CreateCode()
 {
     var code = new Random().Next(1, 999999).ToString();
     code = code.PadLeft(6, '0');
     return code;
 }
開發者ID:yeshusuper,項目名稱:Flh,代碼行數:6,代碼來源:IMobileManager.cs

示例2: CreateBackup

        /// <summary>
        /// Creates a copy of the given file, inserting a number between the
        /// filename and extension
        /// </summary>
        /// <param name="file">The file to create a copy of</param>
        /// <returns>The full name of the copy</returns>
        private static string CreateBackup(FileInfo file)
        {
            string theDirName = file.DirectoryName;
            string theFileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(file.Name);
            string theExt = file.Extension;
            string theRandom = new Random().Next().ToString();
            theRandom = theRandom.PadLeft(5, '0');
            theRandom = theRandom.Substring(theRandom.Length - 5);

            string theBackupName = theDirName + System.IO.Path.DirectorySeparatorChar
                + theFileNameNoExt + "." + theRandom + theExt;

            File.Copy(file.FullName, theBackupName, true);

            return theBackupName;
        }
開發者ID:EAWCS1,項目名稱:SUITT,代碼行數:22,代碼來源:ProjectTransactionCmd.cs

示例3: Init

        /// <summary>
        /// 初始化
        /// </summary>
        private void Init()
        {
            if (string.IsNullOrEmpty(this.logginName))
            {
                this.logginName = "DefaultZhu";
            }

            string ret = string.Empty;
            ret = this.logginName;
            if (ret.Length <= 10)
            {
                ret = ret.PadLeft(10, '6');
            }
            else
            {
                ret = ret.Substring(ret.Length - 10, 10);
            }

            string timeStr = DateTime.Now.ToString("yyMMddHHmmssfff");

            string randomCodeStr = new Random().Next(0, 99999).ToString();

            if (randomCodeStr.Length < 5)
            {
                randomCodeStr = randomCodeStr.PadLeft(5, '0');
            }

            this.trackId = ret + timeStr + randomCodeStr;
        }
開發者ID:HelloAmy,項目名稱:01component,代碼行數:32,代碼來源:TrackID.cs


注:本文中的System.Random.PadLeft方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。