小编Lea*_*ner的帖子

使用Linq在C#中列出操作

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace ConsoleApplication1
{

    public class Class1  
    {
       static void Main(string[] args)
       {
           List<Car> mylist = new List<Car>();
           Car car1;
           Car car2;
           Car car3;

           car1 = new Car()
           {
               make = "Honda",
               id = 1
           };
           car2 = new Car()
           {
               make = "toyota",
               id = 2
           };

           car3 = new Car()
           {
              make = "Honda",
              id = 3,
              color = "red"
           };

           mylist.Add(car1);
           mylist.Add(car2);
           **////mylist.Where(p => p.id == 1).SingleOrDefault() = …
Run Code Online (Sandbox Code Playgroud)

c# linq

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

XMLTextReader不读取元素内容

static void ReadXml()
{
    string a= null;
    double b= 0;
    double c= 0;
    XmlReader xmlReader = new XmlReader("Testxml.xml");
    xmlReader.
    using (xmlReader)
    {
        if (xmlReader != null)
        { 
            while (xmlReader.Read())
            {
                if (xmlReader.NodeType == XmlNodeType.Element)
                {
                    switch (xmlReader.Name)
                    {
                        case "a":
                            a = xmlReader.ReadElementContentAsString();

                            break;
                        case "b":
                            b = double.Parse(xmlReader.ReadElementContentAsString());

                            break;
                        case "c":
                            c = double.Parse(xmlReader.ReadElementContentAsString());

                            break;
                    }
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

TestXML内容:

<a><b>26a83f12c782</b><c>128</c><d>12</d></a>
Run Code Online (Sandbox Code Playgroud)

情况b从未被击中.但是如果我在b的结束元素之后添加一个空格,则会触发案例b.现在如何在不更改xml文件的情况下使其工作?

c# xmltextreader

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

Unity构造函数参数

class Entity:IEntityName
{
    #region IEntityName Members

    public string FirstName { get; set; }
    public string LastName { get; set; }
    #endregion
}

public class Person:IPerson
{
    public IEntityName EntityName;

    public Person()
    {
    }

    public Person(IEntityName EntityName)
    {
        this.EntityName = EntityName;
    }

    public string ReverseName()
    {
        return string.Format("Your reverse name is {0} {1}",EntityName.LastName, EntityName.FirstName);
    }

    public override string ToString()
    {
        return string.Format("Name is {0} {1}", EntityName.FirstName, EntityName.LastName);
    }
}

// Main Method

private static string DisplayReverseName(string fName,string lName)
{
        IUnityContainer container …
Run Code Online (Sandbox Code Playgroud)

c# unity-container

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

C#集合

int[] mylist = { 2, 4, 5 };
IEnumerable<int> list1 = mylist;
list1.ToList().Add(1);
// why 1 does not get addedto list1??
Run Code Online (Sandbox Code Playgroud)

c# ienumerable

2
推荐指数
1
解决办法
372
查看次数

从其他应用程序调试到C#代码

我正在从QTP加载一个DLL(c#).是否可以在qtp测试开始时调试c#代码.

c# qtp

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

增加文本框名称中的数字

public void test()
    {
        List<int> list = new List<int>();
        list.Add(1);
        list.Add(2);
        list.Add(3);
        for (int i = 1; i <= list.Count; i++)
        {

            textBx.Text = list[i].ToString();
            // I want it to be textBx1.Text = list[1].ToString();
                               textBx2.Text = list[2].ToString();
                               textBx3.Text = list[3].Tostring();
                               etc.
              // I can't create textbox dynamically as I need the text box to be placed in specific places in the form . How do I do it the best way? 


        }


    }
Run Code Online (Sandbox Code Playgroud)

c#

0
推荐指数
1
解决办法
2891
查看次数

IList <T> vs IEnumerable <T>:为什么这个赋值无效?

大象:动物....

IList<Elephant> elephants = new List<Elephant>();
IEnumerable<Animal> animalList = elephants;
Run Code Online (Sandbox Code Playgroud)

这工作正常,但..

IList<Elephant> elephants = new List<Elephant>();
IList<Animal> animalList = elephants;
Run Code Online (Sandbox Code Playgroud)

抛出错误.这是为什么?

c# ienumerable

0
推荐指数
1
解决办法
712
查看次数

标签 统计

c# ×7

ienumerable ×2

linq ×1

qtp ×1

unity-container ×1

xmltextreader ×1