|
venkat456 wrote: Why is there a discrepancy in behavior?
Its to do with default value for value types and reference types. You need to call 'new' on reference types to create instances.
|
|
|
|
|
Thanks a lot!
I still feel this is wrong. For example if you are using generics, the code has to first detect if the generic type is ReferenceType and if it is, extra calls to new should be made.
I see that structs cannot be made a generic type but the problem still exists for primitive types like int, double...
T xGeneric = new T[10];
if(!(xGeneric is System.ValueType))
{
for(int i =1; i<10;i++)
{
xGenric[i] = new T();
}
}
|
|
|
|
|
venkat456 wrote: I still feel this is wrong.
How is this wrong? Value types are created inline and that's why creating an array of valuetypes results in them being initialized with default values. An array of reference types stores just that, references to instances on the heap, so they obviously get initialized to null.
If you still think that's wrong, consider the following C++ snippet.
int arr[10];
vs
int **arr = new int*[10];
The second statement will create an array of int * pointers, all initialized to NULL. You can consider reference types similar to that.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi,
I am with a small problem in my application, I have a forn with two userControl, created dynamically and I need to know with I do to draw a line to connect the two userControls.
|
|
|
|
|
I've got 2 columns, Column Catagory, and Column Item. I've got them displaying from drop down boxes, but when I pick a catagory, I dont know how to force the Item Column to update for the items from the selected Catagory. I hope that made sense... (no, I'm not doing this for homework, and my database doesn't actually involve cars)
[Catagory] [Item]
|Car| |Acura|
|Truck| |Accord|
|Tacoma|
Hopefully the above is a reasonable "view" of what I've got.
There is a catagory table, and an item table. The item table has the catagory number from catagory table with each item. Thanks for the help.
|
|
|
|
|
Hi,
DataSet ds;
DataViewManager dsview;
In the form_load write this:
string constr = "Data Source=KALPANA\\KAL; Trusted_Connection = yes;Database=Northwind";
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter da1 = new SqlDataAdapter("SELECT * FROM category", con);
ds = new DataSet("category");
da1.TableMappings.Add("Table", "category");
da1.Fill(ds);
SqlDataAdapter da2 = new SqlDataAdapter("SELECT * FROM item", con);
da2.TableMappings.Add("Table", "item");
da2.Fill(ds);
string dt = "";
for (int i = 0; i < ds.Tables.Count; i++)
{
dt += "Table Mappings" + i.ToString() + " " + ds.Tables[i].ToString() + " ";
}
//MessageBox.Show(dt);
DataRelation relcatitem;
DataColumn colmast;
DataColumn coldet;
colmast= ds.Tables["category"].Columns["catid"];
coldet = ds.Tables["item"].Columns["catid"];
relcatitem = new DataRelation("relcatitem", colmast, coldet);
ds.Relations.Add(relcatitem);
for(int j=0;j
|
|
|
|
|
Hi,
Reply me whether my code is works for u or not.By seeing ur question i tried that program.
|
|
|
|
|
Hi all,
I am trying to develop a text mining engine and in it i need to work on large number of files...and deal with lots of words... i ve made a word class which has following variables
public string term;
public int df;
public ArrayList tf = new ArrayList();
public ArrayList docID= new ArrayList();
public static int count;
here term is the variable wich contains the actual value of the word. now when user queries for a word i need to search all these terms and find out whether the term user wants exists or not....
i ve this word class sorted w.r.t the "term" variable so it means that i can apply binary search for finding the user query.....i m doing this by adding all the term variables of the class in an arraylist and then applying binary search over it....but the problem is that i need to know the index of the arraylist where the user's queried term exists.....and i dont know the way to find out the index i ve added the sample chunk of code here.....anyone plzz help
for(int i = 0; i < Terminology .count; i ++ )
{
allTerms.Add(word[i].term);
}
for(int j = 0; j < queryList.Count; j ++)
{
if(allTerms.BinarySearch(queryList[j]) >= 0)
{
need to know the index of allTerms ArrayList.
}
}
looking forward for help
Regards,
|
|
|
|
|
Ehh, BinarySearch returns the index. If it just indicated if the item was present or not it would have returned a bool.
It is also worth noticing that in case the item is not found, the return value indicates the position the item should have been at if it was present (useful for inserting in the list after it is sorted).
All of this is in the MSDN documentation.
|
|
|
|
|
i really thought that it just returns a bool value....now i understand a little bit....but it wud b really helpful if u illustrate it with a little example
thxx in advance
regards,
|
|
|
|
|
Did you look at MSDN[^] as I wrote? Always look in MSDN first - it is the official documentation for the .NET Framework, and it contains a decent amount of samples.
|
|
|
|
|
Hello, I have looked everywhere and can not find an example of how to mimmic the right click "save picture as" in Internet Explorer. I am building my own tabbed web browser and want to right click an image and have the "save picture" dialog box pop up. I am using VS 2005. Thank you for any information.
|
|
|
|
|
How are you implementing HTML rendering?
If you're just using the MS browser control, this is difficult. It'd depend mostly on having an API hook into mapping between x, y coords and rendered elements within the control. If there's one, it's a pretty easy task (ask).
If you wrote the HTML page rendering yourself, you probably know how to do this already, but just inspect the x, y coords from the right-click event args and see if it falls within the bounds of an image. If it does, you've already rendered the image, so getting a handle to the stream and writing it to disk should be pretty easy.
|
|
|
|
|
If you want complete control you can use the WebBrowser.Document.GetElementFromPoint method. This will return a reference to the HtmlElement under the mouse. Check that the HtmlElement.Name is IMG (i.e. an image tag), if so then you can use HtmlElement.GetAttribute("src") to retrive the url of the image.
You can then use the System.Net.WebClient.DownloadFile method to actually download the file when the user has specified where the image is to be saved.
You know you're a Land Rover owner when the best route from point A to point B is through the mud.
Ed
|
|
|
|
|
Hi,
Due to the fact we got billed double the monthly cost this month, i want to write a small console app that will run in the background and monitor traffic (total/daily/monthly) for the 3 machines on my home network (mainly the kids) can anyone point me in the right direction? Classes or Tutorials i should be looking at? Because i cannot find a thing on it.
I'm hoping it goes as far as accessing some of the Windows API or similar and does not involve things like network card driver wrapping or what have you. If it does i will start looking at commercial software.
These small clip video sites must be taking their toll!.
|
|
|
|
|
Take a look into WMI. There's a .NET wrapper for it. It's basically the same stuff you'd get through perfmon.msc, but an API into it. The WMI writer API for .NET is horribly sparsely documented, but the read API isn't too bad.
Start here[^].
|
|
|
|
|
Excellent just what i need to get started, thank you.
|
|
|
|
|
|
Darren,
Thanks for posting your findings. I'm sure someone will really, really appreciate that.
Isn't there some Yahoo Widget or something somewhere that will let you do this without writing it yourself? Seems like that may be much easier if you only need simple "how much bandwidth am I using right now" functionality.
Stephan
|
|
|
|
|
I found a few commercial programs and possibly some free ones too but i dont want the kids to feel im intruding, since the two that use the other computers are 12 and 14 they might feel a bit child like.
So basically i wanted to stick it in there without them noticing, have it run at startup and send results to a php script or little server running on my machine or laptop.
There are three more reasons too:
1. I wanted to analyse what it was. interested to see if its streaming video from these YouTube or similar small clip sites or if it was something else, 73GB in a month works out at 5.5 days solid full speed.
2. I have a thirst for knowlege and love programming.
3. I am thinking about writing another desktop app that does multiple funky things for you so this could be another thing to add to it (2 for the price of one )
Darren
|
|
|
|
|
I'm reading chapter 1 of Lippman's C# Primer. He talks about using the
"-t" option. Could some one please elaborate what this means and why I would want to do it... thanks a lot
|
|
|
|
|
-t option for what?
|
|
|
|
|
It means that when you can't figure something out, you should take a break for some tea. Hence the -t. You know, dash off and get some tea.
Chris Meech
I am Canadian. [heard in a local bar]
The America I believe in has always understood that natural harmony is only one meal away from monkey burgers. [Stan Shannon]
GOOD DAY FOR: Bean counters, as the Australian Taxation Office said that prostitutes and strippers could claim tax deductions for adult toys and sexy lingerie. [Associated Press]
|
|
|
|
|
Tracing is running with additional back-end output. You should be able to figure out what's going on based on this. In C#, System.Debug.Trace is a static class that drives trace output.
The C# compiler (csc) doens't have a -t command line option. What program is at the beginning of the command line that Lippman is quoting here?
|
|
|
|
|
I dont know if there is any option -t but there is a command line option /t that specifies the type of target assembly i.e. whether its exe,dll or module.
Wasif Ehsan.
|
|
|
|