|
That's not C# code. Pascal?
Why do you think that the code needs to ne optimised?
---
single minded; short sighted; long gone;
|
|
|
|
|
yes, may be Pascal, because that is a test in interview. i cannot finish the test.
|
|
|
|
|
So you want someone else to finish it for you, so that you can get a job doing something that you don't have the sufficent knowledge of?
---
single minded; short sighted; long gone;
|
|
|
|
|
oh no, why do you think that? i fail. but i want to know how to optimize it?
|
|
|
|
|
svincoll4 wrote: oh no, why do you think that? i fail.
Oh, sorry. Because it's not that uncommon that people try things like that, and you didn't speak of the test in the past tense.
svincoll4 wrote: but i want to know how to optimize it?
Well, that depends on the language used, and what the rest of the code looks like.
You could perhaps use a pointer to clear the array faster. Loop unraveling is another optimising method that would simply replace the loop with 101 assignment statements.
However, the most efficient might be if the code that is going to use the array could be altered to not needing the array to be cleared at all, then the loop could simply be removed.
If it's a newly created array, it might not need clearing at all. Some languages automatically clears new arrays on creation, so clearing it again would be completely pointless.
---
single minded; short sighted; long gone;
|
|
|
|
|
svincoll4 wrote: i want to know how to optimize it?
Do you have the foggiest idea what loop unrolling is? That is a general optimization you can use for the loop, but why bother. The compiler will do it for you.
"Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus
|
|
|
|
|
svincoll4 wrote: that is a test in interview. i cannot finish the test.
And you expect people here to help you cheat on an interview test, shame on you!
"Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus
|
|
|
|
|
Playing Devils advocate here - if he had googled the answer and found it, without explicitly asking the question - would that have been OK?
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
|
Malcolm Smart wrote: if he had googled the answer and found it
It would demonstrate a willingness to learn and a capacity to find answers to questions without always turning to ask someone. It's called initiative and is a skill all [good] software developers have.
The early bird who catches the worm works for someone who comes in late and owns the worm farm. -- Travis McGee
|
|
|
|
|
Paul Conrad wrote: svincoll4 wrote:
that is a test in interview. i cannot finish the test.
And you expect people here to help you cheat on an interview test, shame on you!
thanks but please review all my post before you say that.
|
|
|
|
|
Looks pretty optimal to me. Only better is to rewrite it in C or assembly.
|
|
|
|
|
PIEBALDconsult wrote: Looks pretty optimal to me.
Same here, only thing I can think of is some loop unrolling, but the gains are probably minimal in this case.
"Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus
|
|
|
|
|
Most languages have a function/method to clear an array: bzero() in C, Array.Clear() in C#.
They will run faster than whatever equivalent code snippet you come up with.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi
I've to transmit live video 4m Server to multiClients and I m working in C# and using UDP. Plz if any1 use windows media services then tell me what steps I should follow 4 transmission of live video?
How would I stream the video.I m not getting help in this matter from net so plz help me out.
thanx
Shanzay
|
|
|
|
|
Hi,
I want to work on developing Visio drawings using the C# language. But I noticed that there is no documentation for doing that. I searched the internet and I found few things that give me nothing in my project. I want to draw some boxes, change their color and connect them together. Please if you can help me, I will appreciate youe effort.
Thanks
|
|
|
|
|
|
hi
I want to validate the date. ie i have 2 columns received date and due date. due date should be greater than received date. I know the problem is simple.
But the actual problem is here i vant to use it om template of datagrid. and there is around 8 received nd due date column.In every column am calling adddate function.Plz help me to validate this.
|
|
|
|
|
static bool isValidDueDate(DateTime receivedDate, DateTime dueDate)
{
if (receivedDate != null && dueDate != null)
{
return dueDate > receivedDate;
}
}
|
|
|
|
|
DaveyM69 wrote: if (receivedDate != null && dueDate != null)
null testing a data type?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
|
What is the difference between array and arraylist
Regards,
LEE
|
|
|
|
|
Array:The Array class is the base class for language implementations that support arrays. However, only the system and compilers can derive explicitly from the Array class. Users should use the array constructs provided by the language.An element is a value in an Array. The length of an Array is the total number of elements it can contain. The rank of an Array is the number of dimensions in the Array. The lower bound of a dimension of an Array is the starting index of that dimension of the Array; a multidimensional Array can have different bounds for each dimension.Type objects provide information about array type declarations. Array objects with the same array type share the same Type object.Type.IsArray and Type.GetElementType might not return the expected results with Array because if an array is cast to the type Array, the result is an object, not an array. That is, typeof(System.Array).IsArray returns false, and typeof(System.Array).GetElementType returns a null reference (Nothing in Visual Basic).Unlike most classes, Array provides the CreateInstance method, instead of public constructors, to allow for late bound access.The Array.Copy method copies elements not only between arrays of the same type but also between standard arrays of different types; it handles type casting automatically.Some methods, such as CreateInstance, Copy, CopyTo, GetValue and SetValue
Arraylist:The capacity of an ArrayList is the number of elements the list can hold. As elements are added to an ArrayList, the capacity is automatically increased as required through reallocation. The capacity can be decreased by calling TrimToSize or by setting the Capacity property explicitly.Indexes in this collection are zero-based.ArrayList accepts a null reference (Nothing in Visual Basic) as a valid value and allows duplicate elements.
|
|
|
|
|
In my application, if you check a checkbox, and then click a delete button, it deletes that data that was next to the checkbox(in my case labels, and the checkbox itself)
it works fine for the first time, if i choose something from the list to delete, it deletes it and the checkbox itself.
but! if i then choose another checkbox, and click delete it doesn't work(at the debugger i can see that it is like the checkbox is not checked, whilst the user checked it)
i guess i have a problem with the fact that its dynamic, but i can't find it
here is the code - long one, but the only relevant functions are DisplayData and DeleteData
please help me;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
namespace AutoDownloader
{
public partial class Form1 : Form
{
public Form1()
{
Initiailize();
}
public void Initiailize()
{
this.Width=800;
this.Height=400;
this.StartPosition= FormStartPosition.CenterScreen;
DisplayData();
Button UpdateList = new Button();
Button AddShow = new Button();
Button DeleteChecked = new Button();
AddShow.Click+=new EventHandler(AddShow_Click);
UpdateList.Click += new EventHandler(UpdateList_Click);
DeleteChecked.Click += new EventHandler(DeleteChecked_Click);
AddShow.Top = 300;
AddShow.Left = 20;
AddShow.Width = 100;
AddShow.Text = "Add New Show";
UpdateList.Top = 300;
UpdateList.Left = 150;
UpdateList.Text = "Update Show List";
UpdateList.Size = UpdateList.PreferredSize;
DeleteChecked.Top = 300;
DeleteChecked.Left = 270;
DeleteChecked.Text = "Delete Checked Shows";
DeleteChecked.Size = DeleteChecked.PreferredSize;
this.Controls.Add(DeleteChecked);
this.Controls.Add(AddShow);
this.Controls.Add(UpdateList);
}
public void DeleteChecked_Click(object sender, System.EventArgs e)
{
DeleteData();
DisplayData();
}
public void AddShow_Click(object sender, System.EventArgs e)
{
AddShowForm subform=new AddShowForm();
subform.ShowDialog();
}
public void UpdateList_Click(object sender, System.EventArgs e)
{
DisplayData();
}
CheckBox[] CheckBoxes; //the checkboxes that later will be initialized
StreamReader ShowDataFile;
Label[] LabelData;
public void DisplayData() // opens text file, reads the data into an array lists, and then creates the check boxes and labels and displays them.
{
ShowDataFile= File.OpenText("c:\\text.txt");
ArrayList ShowsData = new ArrayList();
string buffer;
while (((buffer = ShowDataFile.ReadLine()) != "" ) && ((buffer != null)))
{
ShowsData.Add(buffer);
}
ShowDataFile.Close();
LabelData = new Label[ShowsData.Count];
CheckBoxes= new CheckBox[ShowsData.Count];
int i;
int index = 0;
for (i = 0; i < ShowsData.Count; i += 4) //start the checkboxes;
{
CheckBoxes[index] = new CheckBox();
this.Controls.Add(CheckBoxes[index]);
index++;
}
for (i = 0; i < ShowsData.Count; i++) //loop that intiliazes the labels;
{ //reads the data into the labels, and adds the controls to the forms.
LabelData[i] = new Label();
LabelData[i].Text = (String)ShowsData[i];
this.Controls.Add(LabelData[i]);
}
int TopMargin = 20;
int LeftMargin = 20;
int label_index = 0;
int checkbox_index = 0;
for (i = 0; i < ShowsData.Count; i+=4 ) //adds checkbox for each 4 lines of array( one dataset)
{
CheckBoxes[checkbox_index].Top = TopMargin;
CheckBoxes[checkbox_index].Left = LeftMargin;
CheckBoxes[checkbox_index].Size = CheckBoxes[checkbox_index].PreferredSize;
for (int y = 0; y < 4 && label_index
|
|
|
|
|
Hai all,
i just want to know about Generic XL Upload with validations.
can some body send me sample urls
Thanks
Subbu.
|
|
|
|