|
Are you required to use arrays? Could you use another alternative dynamic data structure like a List<t> ?
"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
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
Firs of all, I prefer array but if you have only solution on list. You can explain.
|
|
|
|
|
The problem with arrays is that they are static in length. Once declared they can't be grown or shrunk unless you re-declare them. So in the first problem (2 arrays) assuming you copy an element from the first array to the second array and then after you have made a copy you check to see if there are any repetitions you will encounter gaps as such:
aray1: |0|1|2|3|2|5| array2: |0|1|2|3| |5|
so unless you waste extra loops to filter out the gaps into a 3rd array, you can't do much.
With a dynamic data structure such as a list, the following answers your problem:
<br />
array2 = new List<int>(array1);<br />
<br />
int repitionCounter = 0;<br />
for (int i = 0; i < array1.Length; i++)<br />
{<br />
for (int j = 0; j < array2.Count; j++ )<br />
{<br />
<br />
<br />
if (array2[j] == array1[i])<br />
{<br />
repitionCounter++;<br />
}<br />
<br />
if (repitionCounter > 1)<br />
{<br />
array2.Remove(array2[j]);<br />
--repitionCounter;<br />
}<br />
}<br />
<br />
repitionCounter = 0;<br />
}<br />
or even better, since you should be taking advantage of the Class methods:
<br />
array2 = new List<int>();<br />
<br />
for (int i = 0; i < array1.Length; i++)<br />
{<br />
if (!array2.Contains(array1[i]))
array2.Add(array1);
}<br />
"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
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
int[] sayilarTwo = new int[10];
int count = 0;
for(int i=0; i<10; i++) {
bool match = false;
for(int j=0; j<i; j++) {
if(sayilar[j] == sayilar[i])
match = true;
}
if(!match) {
sayilarTwo[count] = sayilar[i];
count++;
}
}
I just bodged that togeather, it will probably work.
There's also probably better ways to do it.
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
thanks a lot, for you responses.
|
|
|
|
|
You might want to try and post this in the ASP.NET forum.
PLEASE reference this at all times when in the forums.
"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
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
Hi,
I'm writing a simple application which requires the user to log on. It displays a logon form and if the user passes the security check, the main form is then displayed.
On my logon form I have this:
static void Main()
{
Application.Run(new Login());
}
If the user passes security, I want the logon form to close leaving the main form open but can I do this? I can hide the form but if I close the main form, the application is still running.
Can anyone help?
Thanks
|
|
|
|
|
The trick is to show the dialog before the Application.Run. Trust me - it works. What you end up with is something like this:
static void Main()
{
using (Login login = new Login())
{
login.ShowDialog();
if (login.IsAuthenticated)
{
Application.Run(new MainForm());
}
}
} Of course, there are a couple of assumptions here. One is that your login form has an IsAuthenticated property, and the other is that your main form is called - well MainForm. Anyway, this should give you the general idea.
|
|
|
|
|
using( System.Diagnostics.EventLog evtLog = new System.Diagnostics.EventLog( ) )<br />
{<br />
evtLog.Source = "MyAppName";<br />
evtLog.WriteEntry( "SomeMessage" );<br />
}
Any reason why this would not work when the current user isn't an Administrator? If this is the case, what is the correct way to enable event logging for non-admins?
Regards,
Daníel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
dabs wrote: Any reason why this would not work when the current user isn't an Administrator?
Yup. The sys admins have locked down your event log - you need to get them to open the privileges on them.
|
|
|
|
|
You can try using impersonation. Ask your administrator to help you with an account that is privileged to write to EventLog.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
Hello everyone,
I am working on a Browser Helper Object and so far I have been able to hook to HTML document elements.
My question is, is it possible to hook to Flash Objects in the HTML? For example would it be possible to detect if a Button in Flash environment has been click?!
Any information on this would be great. Thank you and happy thanks-giving everyone.
Khoramdin
|
|
|
|
|
Hey all i need help in making an OCR software in C#. Currently i am on a basic stage and finding stuff from where to start i just have basic knowledge about OCR so if u guys have any references from where i can find appropiate information so tell me.
Vicky Shah
Vicky Shah
|
|
|
|
|
Here's a link[^].
Pay particular attention to items 2 & 3.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
|
Hi everyone.
I just started developing a very simple mailchecker application, which runs in the background and checks for new e-mails on a certain account every 2 minutes.
Or, that was the plan. When the app connects to the POP3 server, it freezes immediately. Here's my code:
private void timer1_Tick(object sender, EventArgs e)
{
MailCheck.Connect("pop.sixhoej.net", 110);
NetworkStream NS = MailCheck.GetStream();
StreamReader SR = new StreamReader(NS);
StreamWriter SW = new StreamWriter(NS);
string output = SR.ReadLine();
if (output == "+OK Hello there.")
{
SW.WriteLine("USER [e-mail address goes here]");
System.Threading.Thread.Sleep(1000);
SW.WriteLine("PASS [password goes here]");
System.Threading.Thread.Sleep(3000);
SW.WriteLine("STAT");
System.Threading.Thread.Sleep(1000);
output = SR.ReadLine();
output = output.Substring(4, 2);
MessageBox.Show("You have " + output.ToString() + " unread mail(s)");
}
} Can you see anything wrong with this code?
Thanks in advance.
Kristian Sixhoej
"Failure is not an option" - Gene Kranz
|
|
|
|
|
Dont use ReadLine. Your app will get stuck if the reply does not end in a newline.
xacc.ideIronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."
|
|
|
|
|
Thanks, it's working now.
Kristian Sixhoej
"Failure is not an option" - Gene Kranz
|
|
|
|
|
Hi,
Is there anyway to add vertical scroll bar in groupbox so that it could scroll down controls added with in?
pardon me for dumb question but since i am not regular to .NET, specially desktop so often get stuck in little things.
|
|
|
|
|
Haven't done this, but I expect the following can work for you:
- create the GroupBox
- add one autoscrolling Panel to it (Panel.AutoScroll)
- add whatever Controls you want to appear in that Panel
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hey all,
I recently completed it some applications which run smoothly and perfectly on the computer i developed it.
However when i run the application elsewhere it throws an exception that it does not in the main computer... what could be possibly happening here?
I have installed IIS on the computer and when i am running the application i go to the project/bin/release folder and run the program, but it does nothing that throw that exception....
I have previously finished some applications on other computers and there are fine but i wonder why this is not working!
Any tips?
Thanks all,
PS: I got some new books and hopefully after reading them and learning how to explode C# i will be able to help out here as much as i am been helped!!!!
Luis E Tineo S
|
|
|
|
|
Perhaps the version of .NET Framework on the other computer is older than the version on the computer the app was developed on.
Try updating the .NET Framework on the other computer to the newest version.
Kristian Sixhoej
"Failure is not an option" - Gene Kranz
|
|
|
|
|
If updating your .Net environment doesn't work, then your application my not have security permissions to do whatever it is trying to do (read/write to the file system, install applications, run third party applications, etc.). Try raising the trust level of the application and running it as an administrator on the computer. Let us know if it works.
Jeff
|
|
|
|
|
kingletas wrote: learning how to explode C#
Generally speaking, C# programs rarely explode.
Division by zero exceptions however may result in unpleasant consequences...
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Hi!
The first and most important tip is to read and understand the exceptions you get!
Just saying "it throws an exception - what can be wrong" is like going to a doctor and telling him "sometimes something hurts. Help me!" .
If you tell us the exception and where it occurrs, we might be able to help you without having to resort to our crystal balls...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|