|
thanx, i just wanted to know whether it is possible or not , cloning means before sending we create a copy of the object and send it to the method. hmmm.. thanx.
|
|
|
|
|
|
prasadbuddhika wrote: cloning means before sending we create a copy of the object and send it to the method.
Which is also passed by reference...
|
|
|
|
|
|
But most of those values are references.
|
|
|
|
|
Everything that is passed is a value in the truest sense. However that value is (most) often a reference to the object rather than the 'value' itself.
The only way to do what the op wants is to create a new object (therefore a new reference) and copy the values the object holds. Where the object's values are also references, new copies of those also need to be created. This needs to be done recursively until all object references have been recreated.
This is known as deep cloning and, as you can see, can be quite an involved and complex task which is why there is no built in Clone method in the framework. The closest we have is ICloneable which has (of course as it's an interface) to be implemented by the creator of the class.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Assume I write a class called Customer. On it are CustomerKey and CustomerName properties. You set the key to the customer's PK and call the SaveChanges method.
The SaveChanges method first calls a private bool method called Validate. If the CustomerName property is not completed, how would you deal with it? Throw an exception? Maybe set an ErrorMessage property?
Bear in mind that this class may never actually be bound to any UI. It may only ever be called from another non-visual class.
Everything makes sense in someone's mind
|
|
|
|
|
What we do is use an Errors collection, and add the fields that failed validation to the collection. The Validate method then returns false. The calling class looks something like
if (customer.Validate())
{
}
else
{
foreach (Error fieldError in customer.Errors)
{
}
}
Don't blame me. I voted for Chuck Norris.
|
|
|
|
|
That's an excellent idea. Thanks!
Everything makes sense in someone's mind
|
|
|
|
|
Throwing exception would be fair enough.
Best wishes,
Navaneeth
|
|
|
|
|
i want to filter something like string type in my textbox but my code is not working..how do i fix this
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
bindingSource1.Filter = "LASTNAME = LIKE% + textBox1.Text";<br />
bindingSource1.Sort = "LASTNAME ASC";<br />
}<br />
<br />
<br />
|
|
|
|
|
According to the example on MSDN[^], you'd need to re-assign the bindinsource to the datagridview;
BindingSource1.Filter = "LASTNAME='Owner'";
BindingSource1.Sort = "LASTNAME ASC";
dataGridView1.DataSource = BindingSource1;
I are Troll
|
|
|
|
|
crisjala wrote: bindingSource1.Filter = "LASTNAME = LIKE% + textBox1.Text";
You might also want to pick up a book on beginners C# and work through it. It seems you have no idea how strings work.
This line should be closer to
bindingSource1.Filter = @"LASTNAME LIKE% " + textBox1.Text;
though using user input directly without validating it could be considered one of the great sins of programming.
|
|
|
|
|
I'm trying to find a cleaner way to reflectively get at the contents of my class that are lists of other classes:
class BigClass
{
public List<LittleClass1> LittleList1;
public List<LittleClass2> LittleList2;
public string BigString;
}
class LittleClass1
{
public string a;
public int b;
}
class LittleClass2 : LittleClass1
{
public string c;
}
To look into BigClass I use
foreach (FieldInfo fi in BigClass.GetFields())
{
if (fi.GetValue(bigClassInstance).ToString().StartsWith("System.Collections.Generic.List"))
{
}
}
It finds the lists, and I can process them from there, but there must be a better way.
|
|
|
|
|
Try the is and as operators rather than string comparisons.
And probably look for IEnumerable rather than List .
|
|
|
|
|
Thank you. I'll put up a big sign on my desk with "is " and "as " and ToString() so I don't have to ask this again.
|
|
|
|
|
|
is it possible to update twitter status from my C# application using textbox?
|
|
|
|
|
Absolutely, since Twitter has an interface built in to everything. In fact, if you write text on a paper tablet it will update your Twitter account also, magically, with no coding at all.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I'm pretty sure it's even built into tiolet paper judging by some of the posts.
Don't blame me. I voted for Chuck Norris.
|
|
|
|
|
Try googling before asking next time. For a question like this, I'd suggest the terms 'Twitter API'. This is the first result.
http://apiwiki.twitter.com/[^]
|
|
|
|
|
...I'm hoping that this is a stupid question:
I'm needing to pull a CLOB field off of an Oracle table. It just so happens that the character string that was input into that CLOB field conforms to an XML Schema, with a few character replacement tweaks that I have to scrub. less than signs have been replaced with amp lt; and greater than signs have been replaced with amp gt;
I mention that because it throws a significant wrinkle into the processing that I have to do. I have to pull a CLOB out of a DataReader's stream, scrub the string, and then dump the string back into a (MemoryStream???) to pass into the XML DOM objects. I have no idea if this is even close to what I need to be doing, as I have very little experience working directly with Streams in this way.
Can someone tell me how they would go about pulling the string data out of the DataReader stream and passing it into an XMLTextReader as a separate stream for parsing?
Am I even on the right path?
"I need build Skynet. Plz send code"
|
|
|
|
|
hi, I create a table with the below code. Everything is okay but I can not set the "identity specification" property to yes.
This is okay without identity parameter
SqlCommand cmd = new SqlCommand(@"Create table ItemStock (Itemno tinyint, Urun nchar(20),Fiyat float, primary key(Itemno))", baglan);
This is not okay with identity parameter
SqlCommand cmd = new SqlCommand(@"Create table ItemStock (Itemno tinyint, Urun nchar(20),Fiyat float, primary key(Itemno), Set Identity_insert(Itemno) on", baglan);
|
|
|
|
|
try somewthing like this:
SqlCommand cmd = new SqlCommand(@"Create table ItemStock (Itemno tinyint IDENTITY(1,1) Primary Key Clustered,
Urun nchar(20),Fiyat float)", baglan);
If it still doesn't work try replacing the type from tinyint to int.
the (1,1) after IDENTITY represents the identity seed(start) and the increment.
|
|
|
|
|
worked fine with tinyint, thank you very much! By the way, I used Primary key(columnname) but you mentioned Primary key Clustured. what is the difference?
|
|
|
|