|
Well, StringBuilder is used when you want to build up a big string by concatinating small bits together. It's used as strings are immutable, that is they can't be changed.
So, if you add two strings together, a third is created and the contents of both are copied over. Obviously this causes problems if you do it repeatedly, and StringBuilder exists to mitigate this performance problem.
In terms of GC, I believe that strings are collected in the normal manner like any other object, that is at some undeterminate point after all references to it no longer exist.Regards,
Rob Philpott.
|
|
|
|
|
You can't change the return values of framework object methods (and indeed, you don't want to) . In your own object methods, you can use StringBuilder internally if necessary, but unless you have a very specific reason for doing so, there's really no reason to return a StringBuilder object.
A StringBuilder is a more efficient object when frequent changes to a given string are made, but it saves you nothing as a return value unless the method being returned to is also going to heavily modify the returned value.
If you're concerned with memory usage, buy a memory profiler, and run your app for a few days to see if this is indeed something that even needs to be considered. You may find that your efforts are best concentrated elsewhere in the code..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi all,
I am a beginner and have many doubts.some of them sorted out but in some i m stuck.here is the one:
i have a databse and a table in that. ex tbl1 with columns firstname and lastname.
i have 2 textboxes on my form and want to populate those text boxes from the table.
i tried one techniquie using datareader but it is showing the last data of the table. i want on formload the first row to be populated on the specific textboxes.
secound problem is that i want to transfer the data in this form to another page as it is and populate controls of another form by value of this form controls.
|
|
|
|
|
1) Use Top 1 Query while you are loading data from DataBase.
Now you got the first row.
2) If you want to transfer the data from one form to another.
Then if you are using MDI form then
You can access All Control like
Form1 obj=new Form1()
Form2 obj2=new Form2()
obj2.TextBox1.Text=obj.TextBox1.Text
If you are opening form from another form then
obj.TextBox1.Text=this.TextBox1.Text
Still it is not resolved then post minimum code required to help you better.Best Regards,
Chetan Patel
|
|
|
|
|
I don't know why you suggest to use top 1 in the select sql statement...There are many ways to manage if your query return multiple rows. Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Hi All,
Can anybody help me what does the below code do and whats the use of new here. Any link also will be fine.
public abstract class BaseCollection<T> : List<T> where T : BaseEntity, new()
{
public bool MapObjects(DataSet ds)
{
if (ds != null && ds.Tables.Count > 0)
{
return MapObjects(ds.Tables[0]);
}
else
{
return false;
}
}
public bool MapObjects(DataTable dt)
{
Clear();
for (int i = 0; i < dt.Rows.Count; i++)
{
T obj = new T();
obj.MapData(dt.Rows[i]);
this.Add(obj);
}
return true;
}
} Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
modified on Friday, February 5, 2010 7:31 PM
|
|
|
|
|
So like, what's the problem?Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
I want to know can we declare inheritance in that way. Whats the use of new(). What does it represent. Is this coding is Inheritance chaining or multi level inheritance. Please help me in uderstading it. Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
BaseCollection inherits from List< T > where T is a class that inherits from BaseEntity and has a public default constructor.
use of the new() keyword in this context: MSDN[^]
more info: MSDN[^]
|
|
|
|
|
Buy a book, look at some websites, this is all well covered. Do the research yourself and you will truely learn, not just parrot and cut & paste. I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hello, I created a custom BindingNavigator Toolstrip with Buttons - Save, MoveFirst, MovePrevious, MoveNext, MoveLast, Edit mode, Add new, Delete and Cancel.
To avoid copying all events to each new Form I like to assemble the toolstrip including the buttons and events into a usercontrol.
I want to embed a BindingSource into this UserControl.
QUESTION: What is the best practise to house a BindingSource into a UserControl?
The end objective is just to drag and drop the usercontrol onto the form and it's just a matter of linking the input controls (textboxes, comboboxes) to this new BindingNavigator control.
Regards Arjen
|
|
|
|
|
How can I make the BindingSource which is inside the UserControl, visible to other controls on the Form?
How do I make the Bindingsource.Datasource property public so it is visible in the Miscellaneous property section of the UserControl?
Regards Arjen
|
|
|
|
|
i'm currently using:
try
{
using (StreamReader reader = new StreamReader(path))
{
return reader.ReadToEnd();
}
}
catch (Exception e)
{
}
i cycle through each file, do what I need to do w/ the code, and then move onto the next on.
Any other ways to move a little faster?
|
|
|
|
|
|
Hi,
1.
File.ReadAllText() does it all in one line.
2.
if the files are large, you may be stressing the memory, possibly without a real necessity. Do you really need all the data of a file in memory at once? or is a sequential read sufficient?
3.
for small files, and assuming the processing is individual without too much common data, use a few threads (no more than 2*Ennvironment.ProcessorCount).
Note: if your processing needs GUI access, you must avoid invalid cross-thread operations[^]
Warning: if you take them from ThreadPool it will take a few seconds before they are all active.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
here's what i have
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
using (var db = new momdbDataContext(Properties.Settings.Default.Remote))
{
var aAuthor = (from a in db.Authors
where a.ID == (int)comboBox1.SelectedValue
select a).FirstOrDefault();
authorFirstTextBox.Text = aAuthor.AuthorFirst.ToString().Trim();
authorLastTextBox.Text = aAuthor.AuthorLast.ToString().Trim();
}
when i look in the debugger comboBox1.SelectedValue has {ID=2,Name="Jim Bob"}
I don't understand how to get the id value of 2 so I can look up that author.
Sorry for all the questions Just not grasping a lot of this stuff yet.
|
|
|
|
|
How are you binding the data to the combobox?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
private void LoadAuthorsCombo()
{
using (var db = new momdbDataContext())
{
comboBox1.DataSource = db.Authors.Select(c=>new{ID=c.ID,Name=String.Format("{0}, {1}",c.AuthorLast,c.AuthorFirst)});
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "ID";
}
}
I simply dragged combo box from the datasource onto the forum. Then to populate it I called the loadAuthorCombo that i made.
|
|
|
|
|
Hi,
SelectedValue will contain the Value, i.e. the value of the property you chose as ValueMember, hence the ID.
Works for all ListControls, i.e. ListBox and ComboBox.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
so i would call a.id == combobox1.valuemember?
I'm still a little confused. sorry
|
|
|
|
|
why don't you try it? why don't you read the documentation?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Hello there,
Would you please explain , how the below method (that is bold) works ?
public class RelayCommand : ICommand
{
readonly Action<object> _execute;
readonly Predicate<object> _canExecute;
public RelayCommand(Action<object> execute)
: this(execute, null)
{
}
public RelayCommand(Action<object> execute, Predicate<object> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
}
[DebuggerStepThrough]
public bool CanExecute(object parameter)
{
return _canExecute == null ? true : _canExecute(parameter);
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public void Execute(object parameter)
{
_execute(parameter);
}
}
I mean , what's the meaning of : this(execute, null) ?
|
|
|
|
|
It calls the constructor below it: it's like base(whatever).
<mod>The point is to avoid duplicating whatever functionality is in the two-parameter method.
|
|
|
|
|
Thanks,
What's the name of these methods ?
Is there a specific name for these methods ?
|
|
|
|
|
It works on constructors only, i.e. methods that:
- have no return type;
- have a name identical to the class name;
- get invoked using the new keyword.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
modified on Friday, February 5, 2010 4:29 PM
|
|
|
|