加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

用WebService实现从指定数组中选择出任意个元素

发布时间:2020-12-17 00:57:41 所属栏目:安全 来源:网络整理
导读:using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Linq;using System.Web;using System.Web.Services;using System.Web.Services.Protocols;using System.Xml.Linq;namespace RandomWS{ /// summary ///
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace RandomWS
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script,using ASP.NET AJAX,uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string[] GenerateRandomColourArray(int numberOfRandomColours)
        {

            string[] colourPalette = { "Red","Blue","White","Black","Green","Yellow","Purple","Pink","Brown","Grey","Orange","Cyan","Magenta" };
            Random random = new Random();
            string[] arr = new string[numberOfRandomColours];

            for (int j = 0; j < numberOfRandomColours; j++)
            {
               int i = random.Next(0,13);
               arr[j]= colourPalette[i];
            }
            return arr;
                

        }

    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读