|
Thanks J4amieC!
1.
I am confused why do you think the code "dic.Values.CopyTo(FooArray, 0)" is the same as the code "dict.Add(1,new Foo(10))"? I think code "dic.Values.CopyTo(FooArray, 0)" will fill array FooArray, and "dict.Add(1,new Foo(10))" will fill dic dictionary instance. They are of different types.
Why do you think they are of the same effect?
2.
"code dic.Values.CopyTo(FooArray, 0) will create 3 instances of Foo class" -- what is wrong? I think not the reference, but the real new copy is created?
regards,
George
|
|
|
|
|
George_George wrote: I am confused why do you think the code "dic.Values.CopyTo(FooArray, 0)" is the same as the code "dict.Add(1,new Foo(10))"
I never said that. Lets go back a bit. You said:
"Then code dic.Values.CopyTo(FooArray, 0) will create 3 instances of Foo class"
and I said that this was not the case, that the code in the lines above are what actuall instantiated the Foo instance, not the act of using the CopyTo method.
George_George wrote: I think not the reference, but the real new copy is created?
Im 99% sure you're copying the references not making a new instance.
|
|
|
|
|
Thanks J4amieC!
1.
"that the code in the lines above are what actuall instantiated the Foo instance" -- sorry my English is not good. And I am confused about, "the code in the lines above" -- which code do you mean? Could you list here please?
2.
J4amieC wrote: Im 99% sure you're copying the references not making a new instance.
I think you are correct. I have written code to verify. Could you help to review whether my code is correct to test only reference, not instance value themselves are copied please?
class Foo
{
public int abc;
public Foo (int i)
{
abc = i;
}
}
public static void Main()
{
Dictionary<int, Foo> dic = new Dictionary<int,Foo>();
dic.Add(1, new Foo(10));
dic.Add(2, new Foo(20));
dic.Add(3, new Foo(30));
Foo[] FooArray = new Foo[3];
dic.Values.CopyTo(FooArray, 0);
FooArray[0].abc = 40;
Console.WriteLine(dic[1].abc);
return;
}
thanks in advance,
George
|
|
|
|
|
Yeah, the code is fine for the test.
|
|
|
|
|
|
A new object is only instantiated when it is contructed with 'new' else they are references.
|
|
|
|
|
Thanks leppie,
I think CopyTo will create new instances, other than just make a copy of the reference, right?
regards,
George
|
|
|
|
|
George_George wrote: I think CopyTo will create new instances, other than just make a copy of the reference, right?
Buzz! Wrong Again!
Here's a little test app to convince you:
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
namespace ConsoleApplication2
{
class Foo
{
public int abc;
public Foo(int abc)
{
this.abc = abc;
}
}
class Program
{
static void Main(string[] args)
{
Dictionary<int, foo=""> d = new Dictionary<int, foo="">();
d.Add(1, new Foo(10));
d.Add(2, new Foo(20));
d.Add(3, new Foo(30));
Foo[] fooArray = new Foo[3];
d.Values.CopyTo(fooArray, 0);
Console.WriteLine(d[1].abc);
Console.WriteLine(fooArray[0].abc);
Console.WriteLine("Same Instance? {0}", (d[1] == fooArray[0]));
Console.ReadLine();
}
}
}
</int,></int,>
Output:
10
10
Same Instance? True
This implies that I have picked the Foo instances with the same abc value (one from the dictionary one from the array), and when I check the for equality (which checks the reference not the value of abc it comes out true.
|
|
|
|
|
|
It will make copies of the references. Not new objects, hence they will be ReferenceEquals.
|
|
|
|
|
Cool leppie!
When dealing with "==" and Equals, how could we judge whether it compares with address equality (i.e. pointing to the same object instance) or compare for the content/value (e.g. Equals from IEquatable interface)?
regards,
George
|
|
|
|
|
Hi All,
I am trying to read a XML file which contains "=" as value of one of the attribute. The compiler throws following error when i am loading this XML using XMLDocument.Load().
'=' is an unexpected token. The expected token is ';'.
Following is the position where i get the error :
<tab name="Blogs" key="http://www.ournhs.nhs.uk/?cat=3&feed=rss2" />
key attribute contains "=" which throws the error.
Can anyone pls guide me in reading this xml.
Cheers
Mani.
First have the WILL then u WILL
modified on Monday, May 19, 2008 7:50 AM
|
|
|
|
|
Its the ampersand thats the problem. & must be encoded as & when writing the document. If the document has been created with an actual & on its own then its not valid Xml.
modified on Monday, May 19, 2008 8:57 AM
|
|
|
|
|
Jamie has the right answer but didn't double up the escaping! & must be encoded as & when placing a URL with query parameters in an XML file (or anywhere else an & character appears).
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
Hi,
I tried to display an image in an image control in VS 2005, every other thing works except the displaying of the image. However, it works with VS 2003. Here's my code:
protected void uploadButton_Click(object sender, EventArgs e)
{
string fileName = FileUpload1.PostedFile.FileName;
fileName = Path.GetFileName(fileName);
string fileFolder = Server.MapPath("~/images/");
string filePath;
bool fileOk = false;
if (FileUpload1.PostedFile.ContentLength > 0)
{
string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName).ToString();
string[] allowedExtensions = { ".gif", ".jpeg", ".jpg", ".png" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOk = true;
if (fileOk == true)
{
if (!Directory.Exists(fileFolder))
{
Directory.CreateDirectory(fileFolder);
}
filePath = fileFolder + fileName;
if (File.Exists(filePath))
{
msgBox.Text = fileName + " " + "already exists on the Web server";
return;
}
FileUpload1.PostedFile.SaveAs(filePath);
Image1.ImageUrl = filePath;
I need help on how to display the image.
Thanks.
Obinna from Nigeria.
//obinnaaj Eof
|
|
|
|
|
|
We are just about to start a new project that is going to get very big!!
In the past i have always used a different assembly for Business objects (with the DAL inside) and presentaion.
We have been thinking about how to structure the new app, and thought about having the DAL and BO in seperate assemblies (to spread the code out), but they need to refernce each other which you cant do.
How do you manage your code files? do you use assemiles or namespaces?
Any good articals that you have seen?
Thanks
|
|
|
|
|
mark_w_ wrote: do you use assemiles or namespaces?
Yes. DAL dll is imported into BLL dlls. BLL dlls are imported into presentation layer.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks for your VERY quick reply ,
but
if i have a singleton in my BLL, and to create it i need to connect to the database (via the DAL), how would i do that?
Edit, the reason i need to do this is to read in what application level permissions the user has once so i dont have to keep going back to the database
modified on Monday, May 19, 2008 6:59 AM
|
|
|
|
|
mark_w_ wrote: but they need to reference each other which you cant do.
This sounds like it's slightly wrong. If you think about it, your business objects should not need to reference your data access layer. Why would your business objects need to know anything about how/where they are saved?
What I've got is an assembly called DataObjects, which is the basic business objects the app uses. They are pretty much dumb classes and don't really do anything beyond serving as storage structures. This assembly references nothing else apart from the basic .net stuff.
I have a DataAccess assembly which contains the classes that do things like load/save the DataObjects, this references the DataObjects assembly.
Then I've got a BusinessLogic assembly. This references both of the others and provides things like validation checks etc.
From the GUI level, the app doesn't reference the DataAccess assembly directly. Instead it references the BusinessLogic assembly and any saves/loads are performed through that.
Simon
|
|
|
|
|
Define an interface assembly to contain your contracts. This library will access no other solution assemblies but will be accessed by most if not all of them.
|
|
|
|
|
Hi,
Using an article from Code Project I have "globalized" my application however I think I have "over done it".
The user can select from English OR Spanish and then I run the following code...
CultureInfo objCI = new CultureInfo(MainForm.culture);<br />
Thread.CurrentThread.CurrentUICulture = objCI;<br />
<br />
this.xrLabelHeader.Text = MainForm.RM.GetString("0312");<br />
this.xrLabelAmtReceived.Text = MainForm.RM.GetString("0194");<br />
this.xrLabelSNumber.Text = MainForm.RM.GetString("0314");
This works fine but now I think I've stuffed it up for users that don't use Spanish or English (in this case en-US) because I haven't returned the culture back to the computers system after setting the text labels etc.
Presumably I should have read the users culture first, changed it whilst setting the text files etc, and then returned the culture back to the computers so that other formatting rules apply (currency symbol etc).
Can someone confirm the above please or point me in the right direction.
Thanks,
Glen Harvy
|
|
|
|
|
I'm not sure why you'd want to change the thread's CultureInfo back after you set it up. In this case you may want to write a ResourceManager wrapper to set various things without changing the thread's CultureInfo.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
I think I may be confusing myself with the UI Culture and the computers culture.
In my application I don't touch the computers culture and therefor I didn't think there would be a problem.
For example. the application's user can chose to set the UI culture to English or Spanish ie the labels/text in the program can be displayed in either English or Spanish. If they are using the program on a German computer then the dates etc will still be in German. As you said, I could have ignored the culture altogether and just used the ResourceManager as a wrapper.
I'm trying to test all this on a VM but it's a bigger task than I imagined because the .Net version is in English so 'OK' is 'OK', not whatever is German for 'OK'.
What triggered my 'panic' was that I have a Kuwaiti prospective customer who wants to get rid of the '$' and presumably use 'KD'. I paniced because I would have expected it to use 'KD' or whatever currecy symbol is appropriate for the users region. Apparently there is no region specific culture for Kuwait so I think my application is performing as it should anyhow.
Thanks for your input - it seems I only needed to talk it through.
Glen Harvy
|
|
|
|
|
In C#.Net2.0, I created one control. I want to use that control in my other application. How to customize the user control in .Net 2.0. Thanks in advance.
|
|
|
|