c#-3.0

An object reference is required for the non-static field, method, or property

﹥>﹥吖頭↗ 提交于 2019-12-31 03:48:14
问题 I recieve an error when building my vs2008 .net 3.5 solution Error 1 An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Request.get' String _XSLTPath = Page.Request.Url.Scheme + "://" + Page.Request.Url.Authority + Page.Request.ApplicationPath.TrimEnd('/') + '/' + "webparts/weatherandtime/weather/xslt/RSSWeatherXSL.xsl"; The Page object seems to be higlighting in green which is not what i want. Can someone explain whats going on? Thanks, 回答1: You

Incomplete XML attribute

ぐ巨炮叔叔 提交于 2019-12-31 03:03:31
问题 I am creating XML out of Dataset by dataset.GetXML() method. I want to add attributes to it XmlAttribute attr = xmlObj.CreateAttribute("xmlns:xsi"); attr.Value = "http://www.createattribute.com"; xmlObj.DocumentElement.Attributes.Append(attr); attr = xmlObj.CreateAttribute("xsi:schemaLocation"); attr.Value = "http://www.createattribute.com/schema.xsd"; xmlObj.DocumentElement.Attributes.Append(attr); xmlObj.DocumentElement.Attributes.Append(attr); But when I open the XML file, I found "xsi:"

Incomplete XML attribute

China☆狼群 提交于 2019-12-31 03:03:06
问题 I am creating XML out of Dataset by dataset.GetXML() method. I want to add attributes to it XmlAttribute attr = xmlObj.CreateAttribute("xmlns:xsi"); attr.Value = "http://www.createattribute.com"; xmlObj.DocumentElement.Attributes.Append(attr); attr = xmlObj.CreateAttribute("xsi:schemaLocation"); attr.Value = "http://www.createattribute.com/schema.xsd"; xmlObj.DocumentElement.Attributes.Append(attr); xmlObj.DocumentElement.Attributes.Append(attr); But when I open the XML file, I found "xsi:"

how to change text in datagridview text on condition .

[亡魂溺海] 提交于 2019-12-31 03:01:17
问题 I am using a datagridview and I want to display do conditional formatting means when I get for a cell M then I want to display Married .I try this but not sucess. Here is my code: private void masterDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { try { for (int i = 0; i <= masterDataGridView.Rows.Count - 1; i++) { String Value = masterDataGridView.Rows[i].Cells[17].Value.ToString(); if (Value == "M") { e.Value = "Male"; } } } catch (Exception ex) { } } 回答1:

Optimized JSON serialiser / deserialiser as an extension method?

最后都变了- 提交于 2019-12-31 02:12:05
问题 I'd like to serialize any object as easily as possible to JSON, and then convert it back to the type=safe object simply. Can anyone tell me what I'm doing wrong in the "FromJSONString" extension method? Edit For your convenience, a complete and functional extension method is below. Do let me know if you see errors. public static string ToJSONString(this object obj) { using (var stream = new MemoryStream()) { var ser = new DataContractJsonSerializer(obj.GetType()); ser.WriteObject(stream, obj)

XML serialization of hash table(C#3.0)

六月ゝ 毕业季﹏ 提交于 2019-12-31 01:48:19
问题 Hi I am trying to serialize a hash table but not happening private void Form1_Load(object sender, EventArgs e) { Hashtable ht = new Hashtable(); DateTime dt = DateTime.Now; for (int i = 0; i < 10; i++) ht.Add(dt.AddDays(i), i); SerializeToXmlAsFile(typeof(Hashtable), ht); } private void SerializeToXmlAsFile(Type targetType, Object targetObject) { try { string fileName = @"C:\output.xml"; //Serialize to XML XmlSerializer s = new XmlSerializer(targetType); TextWriter w = new StreamWriter

byte[] and efficiently passing by reference

拈花ヽ惹草 提交于 2019-12-30 18:55:51
问题 So this is in relationship to dealing with the Large Object Heap and trying to minimize the number of times I instantiate a byte[]. Basically, I'm having OutOfMemoryExceptions and I feel like it's because we're instantiating too many byte array's. The program works fine when we process a couple of files, but it needs to scale, and it currently can't. In a nutshell, I've got a loop that pulls documents from a database. Currently, it's pulling one document at a time and then processing the

Extension methods overloading in C#, does it work?

半城伤御伤魂 提交于 2019-12-30 18:46:12
问题 Having a class that has a method, like this: class Window { public void Display(Button button) { // ... } } is it possible to overload the method with another one that is more broad, like this: class WindowExtensions { public void Display(this Window window, object o) { Button button = BlahBlah(o); window.Display(button); } } What happened when I tried is that I have infinite recursion. Is there a way to make that work? I want the extension method to be called only when the other method can't

uniqueidentifier Equivalent DataType In C#

怎甘沉沦 提交于 2019-12-30 17:07:18
问题 what is uniqueidentifier (Sql server 2005) equivalent in C# 3.5 datatype ? 回答1: It should be System.Guid or Nullable<Guid> 回答2: There is a page on MSDN called Mapping CLR Parameter Data that answers your question and other similar questions you might have. 回答3: System.Guid.NewGuid() 回答4: Use System.Guid Example : public string CustID { get; set; } public System.Guid ActivationCode { get; set;} 来源: https://stackoverflow.com/questions/2743700/uniqueidentifier-equivalent-datatype-in-c-sharp

Can I get the instances of alive objects of a certain type in C#?

醉酒当歌 提交于 2019-12-30 10:28:18
问题 This is a C# 3.0 question. Can I use reflection or memory management classes provided by .net framework to count the total alive instances of a certain type in the memory? I can do the same thing using a memory profiler but that requires extra time to dump the memory and involves a third party software. What I want is only to monitor a certain type and I want a light-weighted method which can go easily to unit tests. The purpose to count the alive instances is to ensure I don't have any