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) 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文件的情况下使其工作?
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) 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) 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) 大象:动物....
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)
抛出错误.这是为什么?