Sunday, July 13, 2014
Thursday, July 10, 2014
[ Microsoft.com ] - XPath Examples
XPath Examples
..................................................................................................................................
This topic reviews the syntax examples that appear throughout the XPath Reference. All are based on the Sample XML File
for XPath Syntax (inventory.xml). For an example of using an XPath expression in a test file, see "Example of Unions ( | )",
at the bottom of this topic.
Thursday, July 3, 2014
[ StackOverflow.com ] - how to post data to specific URL using WebClient in C#
how to post data to specific URL using WebClient in C# - Stack Overflow
string URI ="http://www.myurl.com/post.php";
string myParameters ="param1=value1¶m2=value2¶m3=value3";using (WebClient wc =newWebClient())
{
wc.Headers[HttpRequestHeader.ContentType]="application/x-www-form-urlencoded";
stringHtmlResult= wc.UploadString(URI, myParameters);
}
[ StackOverflow.com ] Cannot set some HTTP headers when using System.Net.WebRequest
When I try to add a HTTP header key/value pair on aWebRequestobject, I get the following exception:
This header must be modified using the appropriate propertyI've tried adding new values to theHeaderscollection by using the Add() method but I still get the same exception...
Monday, June 23, 2014
[ DatabaseJournal.com ] - Dealing with MS SQL Tables that contain Duplicate Rows
Dealing with MS SQL Tables that contain Duplicate Rows — DatabaseJournal.com
Dealing with MS SQL Tables that contain Duplicate Rows
Every so often, you might have to deal with tables that contain duplicate rows. In one case, you might only need to identify the duplicate rows. In other cases, you might need to remove the duplicate rows. This article will show you some different techniques for dealing with duplicate rows.
[ StackOverflow ] - Use ListForEach to add element to HashTable
Try this:
Although, there's really no reason not to use avalueList.ForEach(x => htable.Add(valueList.FindIndex(y => y == x), x));forhere
for(var index =0; index < valueList.Count; index++){ htable.Add(index, valueList[index]);}
[ StackOverflow ] - Know if an attribute contains a value in HTMLAgilityPack's C# Node Collection
xml - What is the correct XPath for choosing attributes that contain "foo"? - Stack Overflow
The link above is quite interesting for HTMLAgilityPack C# beginners, helps a lot !
Another thing to note is that while the XPath above will return the correct answer for that particular xml, if you want to guarantee you only get the "a" elements in element "blah", you should as others have mentioned also use
/bla/a[contains(@prop,'Foo')]This will search you all "a" elements in your entire xml document, regardless of being nested in a "blah" element
//a[contains(@prop,'Foo')]
[ HTML Agility Pack on Codeplex.com ] - Html Agility Pack - Problem selecting within a node
Check out the link for more information
[ Microsoft's MSDN ] - Recommended Tags for Documentation Comments
Recommended Tags for Documentation Comments (C# Programming Guide)
The C# compiler processes documentation comments in your code and formats them as XML in a file whose name you specify in the /doc command-line option. To create the final documentation based on the compiler-generated file, you can create a custom tool, or use a tool such as Sandcastle.
Here are some Recommended Tags for Documentation Comments
[ Microsoft's MSDN ] The Summary Tag in C#
The <summary> tag should be used to describe a type or a type member. Use <remarks> to add supplemental information to a type description. Use the cref Attribute to enable documentation tools such as Sandcastle to create internal hyperlinks to documentation pages for code elements.
The text for the <summary> tag is the only source of information about the type in IntelliSense, and is also displayed in the Object Browser Window.
Compile with /doc to process documentation comments to a file. To create the final documentation based on the compiler-generated file, you can create a custom tool, or use a tool such as Sandcastle.
Thursday, June 19, 2014
[ Stack Overflow ] What is the difference between explicit and implicit type casts?
Explicit cast:
int x =0;float y =3.8f; x +=(int) y;//Explicit cast.This tells the compiler that the cast was intentional and that you know that the fractional part will go lost. The compiler won't complain.
Implicit cast:
int x =0;float y =3.8f; x += y;//Implicit castThe compiler will complain because the fractional part will be lost when converting float to int.
c# - What is the difference between explicit and implicit type casts? - Stack Overflow
Explicit cast:
int x =0;float y =3.8f; x +=(int) y;//Explicit cast.This tells the compiler that the cast was intentional and that you know that the fractional part will go lost. The compiler won't complain.
Implicit cast:
int x =0;float y =3.8f; x += y;//Implicit castThe compiler will complain because the fractional part will be lost when converting float to int.
[ C# Reference ] Explicit Reference
The explicit keyword declares a user-defined type conversion operator that must be invoked with a cast. For example, this operator converts from a class called Fahrenheit to a class called Celsius:
[ Stack Overflow ] c# - What is the difference between explicit and implicit type casts?
c# - What is the difference between explicit and implicit type casts? - Stack Overflow
What is the difference between explicit and implicit type casts?
What's the difference between the President of the United States and the President of Canada?
Since there is no President of Canada, it's hard to answer the question. The right thing to do is to push back and ask for clarification of the question. By "the President of Canada", does the questioner mean the Queen (ceremonial head of state), the Governor General (who can veto bills) or the Prime Minister (who effectively acts as the executive), or something else? Hard to say without clarification.
And even with clarification, it's a vague question. What differences do you want to know about?
Since there is no such thing as an "implicit cast" in C# it is hard to answer your question. In C#, casting is an operator. So I'll push back on it.
Did you mean to ask "what's the difference between an explicit conversion and an implicit conversion?" Or did you mean to ask about the semantics of the cast operator? Or the difference between the cast operator and other type conversion operators? Or situations in which cast operators can be "implicitly" inserted into your code by the compiler? (For example, the foreach loop and the += operator can both implicitly insert an invisible cast.)
Friday, June 13, 2014
[ Stack Overflow ] - c# - httpWebRequest (The underlying connection was closed: The connection was closed unexpectedly.)
In beginning coding in C# DotNet, we usually come across such errors, and it's good to look into them, see link below for more details
.NET has a bug where it expects that the server will include a
Connection: closeresponse header if it will close the connection after the response is complete. If the server closes the connection without theConnection: Closeheader (entirely valid per RFC2616), .NET will encounter the closed connection when attempting to send the next request on the connection and it will throw this exception. What .NET should be doing is silently creating a new connection and resending the request on that new connection.
