As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
For my parser i want to (depending on user input) save parse stats for the sites a user chooses to parse.
So lets say the user chooses site A, site B and site D:
I then from my threads want to be able to add different statitsitcs like; links parsed, pages parsed, duplicates found, etc. (so basically int values for the sites).
How would i create this into c#?
My idea is to make some kind of multidimensional array?
Is there a better way?
Any suggestions are very welcome :)
I would create a class that encapsulates the statistics and than use a dictionary with a website name as key.
public class Statistics
{
public int PagesParsed { get; set; }
}
var collection = new Dictionary<string, Statistics>();
collection.Add("Site A", new Statistics { PagesParsed = 42 });
var siteAStatistics = collection["Site A"];
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
In C# how can I open the text file , search for string "mystring" and if string is there then set variable Vara = 1 else Vara= 0 .
Thanks in advance
Quick & dirty using System.IO.File.ReadAllText:
int Vara = File.ReadAllText(path).Contains("mystring") ? 1 : 0;
won't do all your exercise to leave you some fun, but here a way to start:
to get all text of a file into a string variable try this:
using System.IO;
string fileContent = File.ReadAllText(#"C:\file.txt");
then here to check if your string is inside:
bool present = fileContent.IndexOf("mystring") >= 0;
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am developing a Windows Application by using C#. I have a form in which I dragged one textBox and one button control. I want to retrieve the user Full Computer Name in the textBox by clicking the button.I wrote some codes for that as..........
private void button1_Click(object sender, EventArgs e)
{
string name = System.Environment.MachineName;
textBox1.Text = name[0].ToString();
}
By clicking the button, it retrieves only the first letter(eg: D for Donald-PC) of the Computer Name by which it starts but I want to retrieve the Full Name(eg: Donald-PC). Please someone help if I have make any change in my codes.Thanks
Just output the full name, not just the 0 index:
textBox1.Text = name;
You are taking the first character of System.Environment.MachineName. You need to do this:
textBox1.Text = System.Environment.MachineName;
As an aside, textBox1 for a control name is really lousy.
You are using char index of array, drop [0] and use just name.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have stored my ArrayList into a multidimensional array to be displayed on the richtextbox.
How do I sort an ArrayList/multidimensional array from the smallest value to the biggest and be displayed on rtbx?
The variables are initialized as:
public static ArrayList dataList = new ArrayList();
public static float[,] finalData = new float[superX.var, 8];
superX.var is int 72.
If possible, instead of the deprecated ArrayList, you should use a List object (in the System.Collections.Generic namespace). The List object has sort methods in which you can specify the sort using a Lambda expression, or you can use LINQ (since it implements IEnumerable)
Using a Lambda expression to order by descending:
var dataListSorted = dataList.OrderByDescending(x => x.PropertyName);
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
couldn't find any article about it. So.. is using '*this.*Chart1..' in asp.net, c# useful? Any time savings or why and when should I use it?
Thanks
It's really not ASP.NET-specific at all. It's just part of C#.
Some people suggest that you should always use it to indicate that you're referring to an instance member, as opposed to a static member or a local variable.
Personally I only use it when the qualification is required for disambiguation, e.g.
public Person(string name)
{
this.name = name;
}
Assuming you're in a situation where it doesn't affect the meaning of the code (i.e. where you're not disambiguating), it will have absolutely no effect on the generated IL, so there's no performance harm or benefit.
Note that in the rare case where you want to call an extension method on the current object, you need to use this as well. For example:
public class Foo<T> : IEnumerable<T>
{
// Implementation omitted
public int CountDistinct()
{
return this.Distinct().Count(); // this is required here
}
}
Three common uses for this, as per MSDN:
To qualify members hidden by similar names.
To pass an object as a parameter to other methods
To declare indexers
Refer to documentation for examples.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Never seen anything like this before. I'm doing a very simple DataReader value assignment.
story.Byline = _r["Byline"].ToString();
But the values of _r["Byline"].ToString() and story.Byline are different after the assignment. Here's the output from the Immediate window:
story.Byline
"Associated Press - FIRST LASTAssociated Press - FIRST LAST"
_r["Byline"].ToString()
"Associated Press - FIRST LAST<br />Associated Press - FIRST LAST"
Why is <br /> being removed?
Calling reader["x"].ToString() you actually calls x' type possibly overridden method ToString().
If you're sure that it's string, use reader.GetString(reader.GetOrdinal("x"))
Well, this is a bit embarrassing:
public string Byline
{
get { return !_elements.ContainsKey("Byline") ? "" : (string)_elements["Byline"]; }
set
{
string _buf = Functions.StripTags(value);
_elements["Byline"] = _buf;
}
}
Incorrect assumptions FTL. Can this question be deleted?