Random rnd = new Random(); myList = myList.OrderBy(x => rnd.Next()).ToList();Or, to take n random elements from a list:
Random rnd = new Random(); myList = myList.OrderBy(x => rnd.Next()).Take(n).ToList();
C#, .Net, MVC, jQuery, JavaScript, HTML, CSS, Umbraco, Phonegap / Cordova, Xamarin, iPhone, iOS, Swift, Android, Windows, apps, websites, Full Stack, ecommerce, Facebook, responsive, front-end. Freelance developer, programmer for web and mobile in Bristol, UK.
Random rnd = new Random(); myList = myList.OrderBy(x => rnd.Next()).ToList();Or, to take n random elements from a list:
Random rnd = new Random(); myList = myList.OrderBy(x => rnd.Next()).Take(n).ToList();
#if DEBUG //do this in debug #else //do something else in release #endif
using System.Xml; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) Bind_ddlCountries(); } private void Bind_ddlCountries() { XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath("countries.xml")); foreach (XmlNode node in doc.SelectNodes("//country")) { ddlCountries.Items.Add(new ListItem(node.InnerText, node.InnerText)); } }and the source xml country list should look like this:
<countries> <country>Algeria</country> <country>Brazil</country> <country>Colombia</country> </countries>You can get the full list of countries I most recently used here.
HtmlTitle title = new HtmlTitle(); title.Text = Title; PlaceHolder1.Controls.Add(title);
<title id="Title1" visible="false" runat="server"><%-- hack to turn the auto title off --%></title>Dirty but effective.
UnifiedFile file = HostingEnvironment.VirtualPathProvider.GetFile(path) as UnifiedFile; string filePath = file.LocalPath;
http://www.mywidgets.com/yellow-widgetsUrl after rewriting:
http://www.mywidgets.com/widgets.aspx?product=yellow-widgetsPicking up the parameters in .Net is easy:
HttpContext.Current.Request.QueryString["product"]
http://www.mywidgets.com/yellow-widgets?utm_source=google&utm_medium=ppc&utm_campaign=yellowwidgetsThis Url is re-written by your URLRW rules, and so you can't grab the utm_x parameters using Request.QueryString["utm_x"]. We can however access the 'unfriendly' Url using
HttpContext.Current.Request.RawUrlwhich using the above example will give us the string
"/yellow-widgets?utm_source=google&utm_medium=ppc&utm_campaign=yellowwidgets"but grabbing the parameter values with ease doesn't seem quite so obvious. We could write some kind of bespoke method to parse through the string to find our params and value. The good news is we don't have to. Using the following code you can take the 'real' or 'unfriendly' Url string, and grab the parameter values with ease:
Uri theRealURL = new Uri(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.RawUrl); string utm_source = HttpUtility.ParseQueryString(theRealURL.Query).Get("utm_source"); string utm_medium = HttpUtility.ParseQueryString(theRealURL.Query).Get("utm_medium"); string utm_campaign = HttpUtility.ParseQueryString(theRealURL.Query).Get("utm_campaign");