小编J-Y*_*J-Y的帖子

如何摆脱列表中的重复,但保持顺序

我在DrRacket中使用Lambda的中级学生,我想知道如何在保持顺序的同时删除列表中的重复项.例如(remove-dup (list 2 5 4 5 1 2))会产生(list 2 5 4 1).到目前为止,我有这个:

(define (remove-duplicates lst)
  (cond
    [(empty? lst) empty]
    [(member? (first lst) (rest lst)) 
     (remove-duplicates (rest lst))]
    [else (cons (first lst) (remove-duplicates (rest lst)))]))
Run Code Online (Sandbox Code Playgroud)

,但由于没有保留订单,因此存在问题.有人能指出我正确的方向吗?谢谢你的时间.

scheme racket

6
推荐指数
3
解决办法
2万
查看次数

MVC - Dictionary需要一个类型为'System.Collections.Generic.IEnumerable`1的模型项

我刚刚开始做MVC 4并且我一直很喜欢它,但是当我试图获取我的数据库(只是NAME和EMAIL条目)以在索引视图中显示其所有条目时,我遇到了麻烦.我收到以下错误:

传递到字典中的模型项的类型为'System.Collections.Generic.List 1[MobileWebFormver2.Models.WebForm1]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1 [MobileWebFormver2.Models.User]'.

我能够将程序连接到数据库,但我几乎被困在这里.我想知道我是否能得到一些帮助.这是我的代码:

用户类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations; 

namespace MobileWebFormver2.Models
{
    public class User
    {
        [Required(ErrorMessage="Please enter name.")]
        public string Name { get; set; }
        [Required(ErrorMessage="Please enter email.")]
        public string Email { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

HomeController(WebForm1是一个数据库条目,包含NAME和EMAIL字段)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MobileWebFormver2.Models;
using System.Data.Entity;

namespace MobileWebFormver2.Controllers
{
    public class HomeController …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc razor

6
推荐指数
1
解决办法
4万
查看次数

将XML反序列化为对象(需要返回对象列表)

开始练习XML和C#,我有一条错误消息"XML文档中存在错误(3,2)".看完文件后,我看不出有什么问题(请注意,我可能因为我是菜鸟而错过了一些东西).我正在使用C#的控制台应用程序.我正在尝试返回一个冒险家列表,只是一个旁注,GEAR元素是可选的.这是我到目前为止:

XML文件 - Test1

<?xml version="1.0" encoding="utf-8"?>
<Catalog>
    <Adventurer>
        <ID>001</ID>
        <Name>John Smith</Name>
        <Address>123 Fake Street</Address>
        <Phone>123-456-7890</Phone>
        <Gear>
            <Attack>
                <Item>
                    <IName>Sword</IName>
                    <IPrice>15.00</IPrice>
                </Item> 
                <Item>
                    <IName>Wand</IName>
                    <IPrice>20.00</IPrice>
                </Item>         
            </Attack>
            <Defense>
                <Item>
                    <IName>Shield</IName>
                    <IPrice>5.00</IPrice>
                </Item>
        </Defense>  
        </Gear>
    </Adventurer>
    <Adventurer>
        <ID>002</ID>
        <Name>Guy noone likes</Name>
        <Address>Some Big House</Address>
        <Phone>666-666-6666</Phone>
        <Gear></Gear>
    </Adventurer>
</Catalog>
Run Code Online (Sandbox Code Playgroud)

C#类

public class Catalog
{
    List<Adventurer> Adventurers { get; set; }
}

public class Adventurer
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string Address …
Run Code Online (Sandbox Code Playgroud)

c# xml

5
推荐指数
1
解决办法
4170
查看次数

web.downloadstring路径中的非法字符

我正在尝试使用正则表达式从网站中检索名称.但是,当我运行程序时,我使用"路径中的非法字符"得到错误.这是代码:

private void button1_Click(object sender, EventArgs e)
{
    List<string> givenNames = new List<string>();

    WebClient web = new WebClient();

    for (int i = 10000; i <= 33852; i++)
    {   
        string numberurl = i.ToString();
        string mainurl = "www.cpso.on.ca/docsearch/details.aspx?view=1&id=+" + numberurl;
        String html = web.DownloadString(mainurl);

        Match m = Regex.Match(html, @"</strong>\s*(.+?)\s*&nbsp;", RegexOptions.Singleline);

        string givenName = m.Groups[1].Value;
        givenNames.Add(givenName);
    }
    listBox1.DataSource = givenNames; 
}
Run Code Online (Sandbox Code Playgroud)

错误发生在String html = web.DownloadString(mainurl);.我尝试使用HttpUtility.UrlEncode但它仍然无法正常工作.我很感激帮助.

c# webforms

4
推荐指数
1
解决办法
5976
查看次数

标签 统计

c# ×2

asp.net-mvc ×1

racket ×1

razor ×1

scheme ×1

webforms ×1

xml ×1