|
Yeah, you can't modify a collection while iterating over it; kind of a chicken-and-egg problem.
One easy solution is to iterate over a copy the collection and modify the original:
foreach (var item in dictionary.ToArray())
{
dictionary[item.Key] = 0;
}
|
|
|
|
|
That is a bit of a bind isn't it ... I'm just rewriting my code with no dictionary. I'm trying to shoehorn functionality out of the wrong approach basically ...
I've just defined a new collection and I'm going to use a List<t> instead. I'm sure I'll find some problems along the way
Jammer
Going where everyone here has gone before!
|
|
|
|
|
After some futzing around i'm going to do this I think. I'm performing this each time:
Dictionary<string, int> FileScoreCopy = new Dictionary<string, int>(FileScore);
Just out of interest. How do you 'delete' this FileScoreCopy once your done with it? I guess some form of proactive garbage collection.
Jammer
Going where everyone here has gone before!
|
|
|
|
|
You don't delete it. When it goes out of scope, it automatically becomes eligible for garbage collection. The .NET garbage collector will reclaim the memory reserved for this object when it runs in the background.
|
|
|
|
|
OK. I need to look into what a destructor is then as that's what I thought they were for.
Thanks,
Jammer
Going where everyone here has gone before!
|
|
|
|
|
Nope, a destructor is only required if you're dealing with unmanaged resources (e.g. closing Win32 files, closing database connections, etc.). For regular managed code where you're not dealing with unmanaged resources, you don't need to implement a destructor.
|
|
|
|
|
Ahhhhhh, that makes total sense now.
I was reading about the generations in the GC the other day ... all very interesting! Much to learn!
Jammer
Going where everyone here has gone before!
|
|
|
|
|
Hi i had a discussion with my friend about OOP and now i want to ask some of you.
The question is:
Knows a file how it can be printed or knows a printer how it can print a file ?
or
Knows a car how it can be repaired or knows a car repair shop how it can repair a car?
or
Knows a clothes how it can be washed or knows a washmaschine how it can wash a clothes
or generally
when have a class a specific ability on its own and
when have only another class a specific ability and need another class to do it
according to a example above:
File.Print( ) or Printer.Print( File ) ?
Car.Repair( ) or CarRepairShop.Repair( Car ) ?
Clothes.Wash( ) or WashMaschine.Wash( Clothes ) ?
|
|
|
|
|
MarkPhB wrote: File.Print( ) or Printer.Print( File ) ?
Car.Repair( ) or CarRepairShop.Repair( Car ) ?
Clothes.Wash( ) or WashMaschine.Wash( Clothes ) ?
My opinion:
- neither, usually a printer doesn't care about the document being sent to him, you'd have to convert any object (file, bitmap, text) to a format the printer can actually print (raw bitmap e.g.)
- CarRepairShop.Repair( Car )
- WashMaschine.Wash( Clothes )
Objects like files, cars, clothes etc. have some properties on their own, but they usually don't have any abilities. A car probably doesn't know how to repair itself, but due to some given properties it may know how it should be accelerated, so Car.Accelerate() might be okay in some circumstances.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
yea thats my opinion too
but my friend say: "Only the class knows what it can be done with it"
for his example: "An object knows how it can be saved in a database".
So he means: Object.Save() and not Database.Save( Object )
|
|
|
|
|
Then you, me and the .NET framework disagree with your friend
Object.Save() makes no sense because where should the object save itself to? A database connection, a file system, over network? The object doesn't know about either of the available streams.
Also, saving an object depends on the place being stored to. For a database it would be a SQLConnection, for the hard disk it would be a FileStream, for network a NetworkStream. So only the streams themselves know how to execute the proper Save() operation.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thx, i knew i was right =)
|
|
|
|
|
Your friend's ideas are not really OOP, because he wants to create monolithic classes that know how to do every aspect of any operation that involves them.
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|
|
HI,
iv'e build an sql Server in SQL Server 2005 Express
and noticed that i do not have the abilty to Manage the Server Notification Services
in The SQL Server 2005 Express.
Is there any way to do this and if not is there another way to Notify
The App About Changes (and not with a thread that will ReFill the Data)?
HELP, Please
THANKS
Have Fun
Never forget it
|
|
|
|
|
As you can see here[^] Notification Services are not available in SQL Express.
only two letters away from being an asset
|
|
|
|
|
THANKS i'll Try Another way
Have Fun
Never forget it
|
|
|
|
|
Hi All,
I'm a little confused at the moment as to why these two apparently 'the same' situations don't work in my code. In this example all works as wanted:
public FileInformation(string filename)
{
FileInfo info = new FileInfo(filename);
_fileName = info.Name;
_fileSize = (info.Length / 1024).ToString() + "KB";
_fileExt = info.Extension.ToUpper();
_fileDate = info.LastWriteTime;
_path = info.DirectoryName;
foreach (DataRow ThisRow in ExtLookUpDS.Tables["ext_look_up"].Rows)
{
if (_fileExt == ThisRow[0].ToString().Trim())
{
_compFormat = Boolean.Parse(ThisRow[1].ToString().Trim());
_midiFormat = Boolean.Parse(ThisRow[2].ToString().Trim());
_audioApp = Boolean.Parse(ThisRow[3].ToString().Trim());
_desc = ThisRow[4].ToString().Trim();
}
}
}
which calls this when it hits the ExtLookUpDS:
private DataSet dsExtensions;
private DataSet ExtLookUpDS
{
get
{
if (dsExtensions == null)
{
dsExtensions = BuildLookups.LoadXmlFile(@"LookUpXML\ext_look_up.xml");
}
return dsExtensions;
}
}
But in this following scenario I'm getting the error "An object reference is required for the non-static field, method, or property" but it compiles ok ...
public void AnalyseTheFilePath(string pathtoanalyse)
{
Regex wordsplitter = new Regex("\\b\\w+\\b",RegexOptions.IgnoreCase);
foreach (Match pathword in wordsplitter.Matches(pathtoanalyse))
{
foreach (DataRow ThisRow in InstrumentsDS.Tables["instrument_lookup"].Rows)
{
if (pathword.ToString() == ThisRow[0].ToString().Trim())
{
}
}
}
}
private DataSet dsInstruments;
private DataSet InstrumentsDS
{
get
{
if (dsInstruments == null)
{
dsInstruments = BuildLookups.LoadXmlFile(@"LookUpXML\instrument_lookup.xml");
}
return dsInstruments;
}
}
I've been trying various things but I'm really butting up against the limits of what I know about C# in order to solve this one at the moment. What am I doing wrong / different in this second example to create this error?
Thanks in advance,
Jammer
Going where everyone here has gone before!
|
|
|
|
|
Ok, its something to do with creating an instance of dsInstruments isn't it ... ?? Adding in:
DataSet InstrumentsDS = new DataSet();
public void AnalyseTheFilePath(string pathtoanalyse)
{
Regex wordsplitter = new Regex("\\b\\w+\\b",RegexOptions.IgnoreCase);
DataSet InstrumentsDS = new DataSet();
foreach (Match pathword in wordsplitter.Matches(pathtoanalyse))
{
foreach (DataRow ThisRow in InstrumentsDS.Tables["instrument_lookup"].Rows)
{
if (pathword.ToString() == ThisRow[0].ToString().Trim())
{
}
}
}
}
Fixes the referencing problem but doesn't actually build the dataset and I don't want to build a new instance of dataset everytime the method AnalyseTheFilePath() is called ...
sheesh ... this is driving me nuts. There is a lot to learn in C# ...
Jammer
Going where everyone here has gone before!
|
|
|
|
|
Ok, I seem to have cracked this now by doing this:
private static DataSet dsInstruments;
private static DataSet InstrumentsDS
{
get
{
if (dsInstruments == null)
{
dsInstruments = BuildLookups.LoadXmlFile(@"LookUpXML\instrument_lookup.xml");
}
return dsInstruments;
}
}
So I was calling a non-static member from a static context. Even thought I've fixed my problem it has now confused me as to what *exactly* static means, I thought i'd worked that out!! More reading to do methinks!
hmm ...
Jammer
Going where everyone here has gone before!
|
|
|
|
|
I wrote a class Cached<T>. When its data is first requested, it runs the stored delegate to initialize the object. With implicit converion I could write something like:
Cached<csvfile> cached = new Cached<csvfile>(delegate(ref CsvFile item){...});
...
CsvFile file = cached;
The problem is that I cannot do something like "file.Save()"; I have to do file.Data.Save(). Since these objects should behave like normal objects of that type, it should be possible to write file.Save().
Is there any way?
(Did I accidentally duplicate some class that .NET BCL already has?)
modified on Sunday, March 9, 2008 9:23 AM
<div class="ForumMod">modified on Sunday, March 9, 2008 9:25 AM</div>
|
|
|
|
|
I'm trying to create an application in C# using the forms designer in Visual Studio 2008. Coming from Java, it's a welcome relief not to have to hand code the whole layout, but there's something that doesn't seem to be working. The 'Dock' setting for components. I have a split pane, inside each pane of which are two more split panes. Whenever I set the main split pain to dock horizontally and vertically (the middle button in the designer), it underlaps the toolbar, and the same happens in the sub-panes - they overlap the drop down box I've set to dock at the top.
Is it best to have just one docking component per panel or is there a way around this? The window looks fine at the default size, but once it's resized nothing changes size to fit.
The code from the designer is at http://mi6.nu/FrmMain.Designer.resx if anyone could take a look and see if I'm doing something wrong. It's probably something simple, but maybe someone else has had a similar problem.
Thanks.
|
|
|
|
|
Hello,
I am using Domain Spaecific language tool with VS2005.I am having some questions related to it...
1). In DslDefinition.dsl design, i have taken a swimlane controller and made the initial height and widh of value 2(inches). But it is not getting reflected when i use the Swimlane object in output application. What else i need to do?
2). In my output application, how can i make sure that the flow eliments should be displayed(aligned) in the same order the added(one after one). As of now every 3rd and fourth eliment aligned at the right side of 1st and 2nd eliment.
Thanks & Regards
Gajesh
modified on Sunday, March 9, 2008 11:42 PM
|
|
|
|
|
can anybody plz help in telling me how to write a file to a cd through a program.....i mean that the program should automatically write a file to a cd without going thru the manual process of starting softwares like nero etc.... if anybody knows this... plz plz send me the source code...i will be very grateful....!!!
greatprateek@gmail.com
Prateek
|
|
|
|
|
Google for XPburn or Imapi
|
|
|
|
|
I am searching for a bettor .net tools for ICR/OMR/OCR.
I have already looked a Pegasus and LeadTools Component for this purpose.
So, If Anybody know about a other company or site info about ICR/OMR/OCR, please advice.
RK
|
|
|
|