複数の携帯電話番号をカンマで区切る

6057 ワード

     #region    
      string[] mobiles = new string[] { "18975887650", "18775887650", "18977487650", "18975887512" };

      /// <summary>
      ///  
      /// </summary>
      /// <returns></returns>
      public string GetMobile()
      {
          string strmobile = "";
          for (int i = 0; i < mobiles.Length; i++)
          {
              strmobile += mobiles[i] + ",";

          }
          if (strmobile.Length > 0)
          {
              strmobile = strmobile.Substring(0, strmobile.Length - 1);
              return strmobile;
          }
          return strmobile;

      }
     
      #endregion

データベースから取得:
      #region  
      /// <summary>
      ///      
      /// </summary>
      public string GetMobileNumber()
      {
          string strmobilenumbers = "";

          DataTable dt = jub.Get_Mobile(mu.MobileNumber);
          // 
          // mobiles = dt.Rows[0]["MobileNumber"].ToString();
          // 
          string[] mobilenumbers = new string[dt.Rows.Count];
          if (dt.Rows.Count > 0)
          {
              // 
              for (int i = 0; i < dt.Rows.Count; i++)
              {
                  DataRow dr = dt.Rows[i];
                  mobilenumbers[i] = dr["MobileNumber"].ToString();// 
                  strmobilenumbers += mobilenumbers[i] + ",";
              }


              if (strmobilenumbers.Length > 0)
              {
                  strmobilenumbers = strmobilenumbers.Substring(0, strmobilenumbers.Length - 1);
                  return strmobilenumbers;
              }
              return strmobilenumbers;
          }
          return strmobilenumbers;
      }
      #endregion