|
I was aware I can only take 5 elements... indeed it was only prototype I built before you gave me idea I should use hashtable... regular usage of this wouldn't be user input 5 strings from console... nor it should be in main at first place... it should be method... probably in separate class that is given array as argument... and it return (Hashtable) which contain unique elements and their count...
My first try before Hashtable was actually 2 dimensional object array... but was tired of casting int in and out for count every time... so I switched to int array+arraylist... don't know which solution is more complex. I'll redo my code now with hash table...
I know about conventions to never give single letter variable names... didn't do it on purpose... and would certainly rename this later if I was happy with approach... I already had bunch of commented code so it was mess... I always first comment things out I don't like... then move them beyond last } and only delete them after I have final release fully debugged...
Sure I got some good read on generics so I hope that will give me some idea...
Thanks guys for help, this was actually one of questions I had to solve on my job interview-test yesterday... other questions were more like this... combined with ADO.NET, few SQL only... and some .Net stuff.... like, what is base class in net... and such stuff...
I messed up this one that is sure...
|
|
|
|
|
I like generics.
Dictionary<string, int> words = new Dictionary<string, int>();
string word;
while ((word = Console.ReadLine()).Length > 0) {
if (words.ContainsKey(word) {
words[word] = words[word] + 1;
} else {
words.Add(word, 1);
}
}
foreach (KeyValuePair<string, int> pair in words) {
Console.WriteLine(pair.Key + " : " + pair.Value.ToString());
}
---
single minded; short sighted; long gone;
|
|
|
|
|
Got it...
public Dictionary<object, int=""> GetUniqueElementCollection(object[] PassedArray)
{
Dictionary<object, int=""> ResultList = new Dictionary<object, int="">();
foreach (object origObject in PassedArray)
{
bool exist = false;
foreach (KeyValuePair<object, int=""> obj in ResultList)
{
if (obj.Key.Equals(origObject)) exist = true;
}
if (exist)
{
ResultList[origObject] += 1;
}
else
{
ResultList.Add(origObject, 1);
}
}
return ResultList;
}
what do you think guys?
|
|
|
|
|
i have created my first game a simple puzzle system, and I'm not an all star with programming yet, i would like to run a a short video when the program is opened, preferably a flash file but its not a major issue if its not, also i don't want this file to run inside a media player such as WMP or Itunes. is this possible and if so any ideas on how to achieve it.
|
|
|
|
|
hi all,
I am a newbie in serial communication program.I have done a small program that can send request and get result from third party device.What i am doing is using do-while to try get data from serialport and using timer to do ReadTimeOut function.Then,if fail to get at the first time,i will retry to get another time.
Now i would like to try using SerialDataReceivedEventHandler (i dun know whether using SerialDataReceivedEventHandler is better than using do-while loop or not)to replace my existing program.I know i can use serialport control.But i am confusing to use it and dun know how to implement it just like my existing program.
Any hits or guides are welcome.
thanks in advance.
regards
cocoonwls
|
|
|
|
|
Dear all,
I'm looking for advice how to create a report. I want to dynamically create an invoice preferably in Word or a PDF. I can find heaps and heaps of code on how to export datagrid's to Excel in VB.NET or ASP.NET , but that is not what I'm after.
I have a datagrid, and I want to export the datagrid to either a word document ( so I can print it later ) or export it to another form and build a report that way.
Can anyone point me in the right direction ?
Cheers,
|
|
|
|
|
hi,
You may try Reportviewer.I am just start to use this tools also ,it seem nice.Just drag it into panel and create a report using report viewer task.Hope this help you
cocoonwls
|
|
|
|
|
Hi guys,
I have a class named Configuration which is basically a collection of configItems.
Each config item has the following:
ID (allows persisting to file/database)
Name (a friendly way of searching for the item)
Value (self explanatory)
At present, ID is an integer type and both Name and Value members are string types.
However, the value may actually represent a boolean, integer, string, decimal and potentially other types.
The annoyance is currently having to cast the value to and from string to whaterver object type is required.
It would be great if the Value member could be the correct object type without having to cast each time.
I guess being able to have a generic member would be ideal but from my knowledge of generics, this doesn't appear possible.
How do you guys approach situations like this? What would you do?
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
View my Blog
|
|
|
|
|
You could create a base class that contains just Id and Name, and create subclasses for each data type.
The base class could contain methods for getting data from each subclass. For example:
public int GetInt32() {
ConfigurationItemInt32 item = this as ConfigurationItemInt32;
if (item == null) {
throw new ApplicationException("Item is not an Int32 value.");
}
return item.Value;
}
---
single minded; short sighted; long gone;
|
|
|
|
|
I am writing to find out how I can escape special characters such as the (') when submitting information into a db using sql. The (') is causing my sql statement to break. Is there some kind of string function to search for these character's in a string and replace them? Please advise. Thanks.
|
|
|
|
|
You should be using paramatized queries and not directly using or concatenating user input to create a query otherwise your database is open to an sql injection attack.
You may find this article usefull:
http://www.codeproject.com/cs/database/SqlInjectionAttacks.asp
Hope this helps
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
View my Blog
|
|
|
|
|
Not sure you're in the right forum - however replacing (') with ('') should work for you. ('') is the single quote twice not the double quote.
|
|
|
|
|
parsing dicom image file to bmp ?
dicom file is a encrpted file which has pixel data aswell as patient data
rajesh
-- modified at 15:18 Wednesday 14th February, 2007
|
|
|
|
|
You are going to have to ask better than that. At least give people enough information so they could be able to attempt to help you.
|
|
|
|
|
Hi,
i'm new developer in C#.. how create a Folder in C# language?
Thanks..
|
|
|
|
|
Use the Directory.CreateDirectory method.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
See: http://msdn2.microsoft.com/en-us/library/system.io.directory_members.aspx
Directory.CreateDirectory(INSERT_FOLDER_NAME_HERE);
Enjoy!
|
|
|
|
|
Hello,
I have created one Window Application using C# which I can successfully install after going throu with the publication process. How can I create a second Window Application which is part of the first Application Installation and the user carry only one installation in order to have both window applications?
Thank you in advance for your help
Khoramdin
|
|
|
|
|
Khoramdin wrote: How can I create a second Window Application which is part of the first Application Installation and the user carry only one installation in order to have both window applications?
Add it to the setup project in the same way as the first. This is easy if both applications are part of the same solution.
|
|
|
|
|
Hello Colin,
Thanx for the reply. I am not sure what you mean by that. Could you give some more detail about this or point me to a tutorial.
Thanx
Khoramdin
|
|
|
|
|
I would integrate matlab with C#, but i don't know why i can do it,
please help me.
|
|
|
|
|
|
I am creating a testing harness for my app and merrily loading assemblies using reflection into a seperate app domain.
What i was hoping to be able to do is unload the App Domain - releasing the file lock on the Assemblies. Allowing me to have write access to rebuild them in Visual Studio.
Unfortunately the app still has locks on the assemblies. Can anyone think of what i might be missing?
The code goes something like this:
1) Assembly assembly = reflectionDomain.Load(filename);
2) AppDomain.Unload(reflectionDomain);
Anyone any clues?
Cheers
Rich
|
|
|
|
|
There is a known issue with file locks when images are involved.
Image.FromFile(fileSpec) keeps fileSpec open; a work-around consists of a small
class that immediately copies the image to another image, and then disposes of the
original.
Maybe that's what you are experiencing...
Luc Pattyn
|
|
|
|
|
How do you generate documentation from the C# file commented properly with a command-line compiler?
Thank you.
Vasini
|
|
|
|