在以下程序中:
class Main
{
static string staticVariable = "Static Variable";
string instanceVariable = "Instance Variable";
public Main(){}
}
Run Code Online (Sandbox Code Playgroud)
在instanceVariable将存储分配给对象实例的记忆里.staticVariable存储在哪里,是存储在对象实例本身还是其他地方?如果它存储在其他地方,内存位置如何连接?
下面是我试过的代码,有更好的方法吗?
public class NutritionFacts
{
public static NutritionFacts.Builder Build(string name, int servingSize, int servingsPerContainer)
{
return new NutritionFacts.Builder(name, servingSize, servingsPerContainer);
}
public sealed class Builder
{
public Builder(String name, int servingSize,
int servingsPerContainer)
{
}
public Builder totalFat(int val) { }
public Builder saturatedFat(int val) { }
public Builder transFat(int val) { }
public Builder cholesterol(int val) { }
//... 15 more setters
public NutritionFacts build()
{
return new NutritionFacts(this);
}
}
private NutritionFacts(Builder builder) { …Run Code Online (Sandbox Code Playgroud) 为什么列表list1Instance和下面代码p的Main方法指向同一个集合?
class Person
{
public string FirstName = string.Empty;
public string LastName = string.Empty;
public Person(string firstName, string lastName) {
this.FirstName = firstName;
this.LastName = lastName;
}
}
class List1
{
public List<Person> l1 = new List<Person>();
public List1()
{
l1.Add(new Person("f1","l1"));
l1.Add(new Person("f2", "l2"));
l1.Add(new Person("f3", "l3"));
l1.Add(new Person("f4", "l4"));
l1.Add(new Person("f5", "l5"));
}
public IEnumerable<Person> Get()
{
foreach (Person p in l1)
{
yield return p;
}
//return l1.AsReadOnly();
}
}
class …Run Code Online (Sandbox Code Playgroud) 在我们的新项目中,我们必须提供搜索功能,以从数百个xml文件中检索数据.我在下面简要介绍了我们当前的计划,我想知道您对此的建议/改进.
这些xml文件包含个人信息,搜索基于其中的10个元素,例如姓氏,名字,电子邮件等.我们当前的计划是创建一个包含所有可搜索数据的主XmlDocument和实际文件的密钥.因此,当用户搜索数据时,我们首先查看主文件并获取结果.我们还将从最近的搜索中缓存实际的xml文件,以便以后可以快速处理simillar搜索.
我们的应用程序是.net 2.0 Web应用程序.
请查看下面的代码并帮助我弄清楚我的Web服务代码中出了什么问题.我想建立一个可以使用JSONP使用的asp.net Web服务.我在客户端使用Jquery来访问该站点.即使在设置了适当的属性后,我的Web服务仍然会发出xml,因为aynch调用失败了.
网络服务
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
[ScriptMethod(ResponseFormat= ResponseFormat.Json, XmlSerializeString=false, UseHttpGet=true)]
public string HelloWorld(int id, string __callback) {
return __callback + "({message: 'Hello World'})";
}
}
Run Code Online (Sandbox Code Playgroud)
Web服务响应:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">test({message: 'Hello World'})</string>
Run Code Online (Sandbox Code Playgroud)
Web.Config中:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> …Run Code Online (Sandbox Code Playgroud) c# ×4
.net ×3
asp.net ×2
.net-2.0 ×1
generics ×1
ienumerable ×1
javascript ×1
jquery ×1
jsonp ×1
search ×1
web-services ×1
xml ×1