It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
My problem is with Xml file, which to look :
This isn't work.
IEnumerable<XElement> stepsList = doc.Elements();
XML file
<OneGoal>
<Goal>100000</Goal>
<StepOne>ewewewe</StepOne>
<StepTwo>wee</StepTwo>
<StepThree>MY</StepThree>
<StepFour>wwwww</StepFour>
<StepFive>ddddw</StepFive>
<StepSix>fcd</StepSix>
<StepSeven>blblblfl</StepSeven>
<StepEight>z dwadddddsssssssssssss</StepEight>
<StepNine>radwds</StepNine>
<StepTen>
blblblblblblb
</StepTen>
<DateDay>18</DateDay>
<DateMonth>7</DateMonth>
<DateYear>2019</DateYear>
</OneGoal>
I want all elements to IEnumberable . Earlier all elements have name 'step'.
How about converting your flat xml to Dictionary<string,string>?
var dict = XDocument.Parse(xml)
.Element("OneGoal")
.Elements()
.ToDictionary(e => e.Name.LocalName, e => e.Value);
Console.WriteLine(dict["StepOne"]);
Use XDocument to load from a file or parse from a string.
var stepList = doc.Descendants();
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I need a simple solution for the problem in C#
Input : Any Body Can Dance
Output : ABCD
string inputString = "Another One Bites The Dust And Another One Down";
string[] split = inputString.Split();
foreach (string s in split)
{
Console.Write(s.Substring(0,1));
}
Check this out:
string s = new string("Any Body Can Dance"
.Split(' ')
.Select(x => x.First())
.ToArray());
Console.WriteLine(s);
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
System.Web.HttpUtility.HtmlDecode not working for test %3cstrong%3ebold %3c/strong%3etest
Output should be <strong>bold </strong>test
I believe you want HttpUtility.UrlDecode in this case.
HtmlDecode is for things like <strong>
You are mixing up html encoding with url encoding. So it is normal that this does not work. Try using HttpUtility.UrlDecode()
Example for Url encoding:
%3cstrong%3ebold%3c/strong%3e
Example for HTML encoding:
<strong>bold</strong>
HttpUtility.HtmlDecode is used for converting HTML entities, e.g.
var sample = "<strong>bold </strong>test";
var result = HttpUtility.HtmlDecode(sample);
// result = "<strong>bold </strong>test"
You're looking for HttpUtility.UrlDecode, I believe, which surrenders:
var sample = "test %3cstrong%3ebold %3c/strong%3etest";
var result = HttpUtility.UrlDecode(sample);
// result = "<strong>bold </strong>test"
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am looking for something like PHP's associative arrays that supports nesting too. For instance, I am creating a Dictionary Object like following:
System.Collections.Specialized.OrderedDictionary userRoles = new System.Collections.Specialized.OrderedDictionary();
userRoles["UserId"] = "120202";
userRoles["UserName"] = "Jhon Doe";
// 2D array Like
userRoles["UserRoles"][0] = "CAN_EDIT_LIST";
userRoles["UserRoles"][1] = "CAN_EDIT_PAGE";
Then I would like to access them by KeyNames instead of index values. Is it possible?
OrderedDictionary uses objects for both keys and values.
To achieve nesting, just set the value to be another dictionary:
userRoles["UserRoles"] = new Dictionary();
Then you can use:
((Dictionary())userRoles["UserRoles"])["MyKey"] = "My Value";
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I was wondering how can I find all the names of functions that are in the program?
Any built in method for this?
Or any hint to how can I find?
stack trace or something like that?
var allMethods = typeof(AnyClass).Assembly
.GetTypes()
.SelectMany(type => type.GetMethods());
var allMethodNames = allMethods.Select(method => method.Name);
Console.WriteLine( string.Join(Environment.NewLine, allMethodNames) );
In order to inspect many assemblies, use next code:
Assembly[] assembliesToInspect = {
typeof(AnyClass).Assembly,
typeof(ClassFromAnotherAssembly).Assembly
};
var allMethods = assembliesToInspect.SelectMany(assembly => assembly.GetTypes())
.SelectMany(type => type.GetMethods());
You can use reflection to open your program or dll and enumerate all types and for each type enumerate all their public methods.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How do i find SiteMap.RootNode.ChildNames title's value equel 'test' in one line?
I don't write linq it doesn't work.
protected SiteMapNodeCollection getParentNodeTitle()
{
SiteMap.RootNode.ChildNames
}
This should do the trick:
var mySiteMap = new SiteMap();
/* Lots of code for populating your SiteMap here */
var nodeTitledTest = mySiteMap.RootNode.ChildNodes.Where(x => x.Title == "test").FirstOrDefault();
This will return the first node with a title equal to "test" or null if no such node could be found.