|
You can try this:
List<string> my = new List<string>();
for (int i=0;i<200000;i++)
my.Add("a");
Console.WriteLine("There are {0} elements to my list",my.Count.ToString());
Console.ReadKey();
The result is: 200000
I hope that help you
|
|
|
|
|
We have now built arrays of over 80,000 lines with over 250 chars per line with no problem and written this to a list box. There seems to be no array size limitation or limitation of the list box. We have tracked our problem down to a problem in the "recursive directory search" see recent post.
-- modified at 6:32 Wednesday 17th January, 2007
|
|
|
|
|
I want to assign the results of an SQL ExecuteScalar to an int. Which is fine when the ExecuteScalar returns a value (i.e the paramater sent to the stored procedure caused the SELECT function to find a valid record).
BUT if the paramater does not pass the SELECT procedure a value that is already in the table the assignment to an int causes an exception (as no record was returned).
Can i do this without using a try/catch block?
Thanks.
|
|
|
|
|
Red_Wizard_Shot_The_Food wrote: I want to assign the results of an SQL ExecuteScalar to an int. Which is fine when the ExecuteScalar returns a value (i.e the paramater sent to the stored procedure caused the SELECT function to find a valid record).
BUT if the paramater does not pass the SELECT procedure a value that is already in the table the assignment to an int causes an exception (as no record was returned).
Can i do this without using a try/catch block?
You could return it as an object and then cast it if the object was not null.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
As far as i know you can't do it without using try catch or an if statement which in this case is the same.
Convertion in .Net assumes that the converted value is not null. So any testing should be done prior
assuming your id in base are not zero-valued i have implemented a function that executed the command and return zero if not found or the desired value.
I have implemented something similar for strings also.
|
|
|
|
|
Sarafian wrote: you can't do it without using try catch or an if statement which in this case is the same.
No it isn't. A try/catch adds a heck of a processing overhead if an exception is raised. Since this is not an exceptional case getting the value as an object then testing for null would be the better option.
Sarafian wrote: assuming your id in base are not zero-valued i have implemented a function that executed the command and return zero if not found or the desired value.
Returning magic numbers is not the solution. Testing for null or DBNull.Value is.
It should also be realised that null is not the same as DBNull.Value .
null is returned if the SELECT statement returned nothing at all. DBNull.Value is returned if the SELECT statement found the row and column, but the column was null .
|
|
|
|
|
Thanks. Didn't know the difference.
|
|
|
|
|
please how can i get from that string "80-247-0092-1 Grada Publishing" to one string first code (ISBN) and to second string everythig gehind this isbn code? ... please help me ... again
-----------------------------
Computer is my hell on earth
|
|
|
|
|
If the ISBN is always followed by a space character, you can use: String.Split(new Char[] {' '}, 2)
"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
|
|
|
|
|
Hi
I was hoping for someone to come out with an idea for a situation i came across..pls bear with me, its a bit long, and i shall explain with code.
this is a sample of my class:
public class Customer<br />
{<br />
private Dictionary<long, Membership> membershipDict;
private Dictionary<long, Address> addressDict;
<br />
public Membership GetMembershipByKey(long key)<br />
{<br />
if (membershipDict.Contains(key))<br />
return membershipDict[key];<br />
}<br />
<br />
public void InsertMembership(Membership membership)<br />
{<br />
if (!membershipDict.Contains(key))<br />
membershipDict.Add(membership.MemberhsipId, membership)<br />
}<br />
<br />
}<br />
My problem is, I would have lots of methods to just retrieve and insert my Dictionaries of memberships and addresses. And there are more of these dictionaries in my Customer Class. I was thinking of replacing these with Generic Method, for example:
public T GetObjectByKey<T>(long key)<br />
{<br />
}
But internally I would need some mechanism to tell me which T is being called. I was thinking of using a Dictionary to keep this info, but its strongly typed, and I cannot use a dictionary to keep a keypair value of Type, and Dictionary<T,K>.
I was thinking of letting my Membership and Address classes inherit from an interface, let's say IModel.
So i would have dictionaries:
private Dictionary<long, IModel> membershipDict;
private Dictionary<long, IModel> addressDict;
so that i can keep a:
Dictionary<System.Type, Dictionary<long, IModel>> typeDict;
but I dont really like this approach. Sorry for the very long explanation, but i hope it explains my dilema. I am looking forward to some great suggestions. Im fairly new with C# and generics. Im just looking for a way to shorten my code. Would hate to have same methods repeating everywhere...
Cheers
|
|
|
|
|
First of all have you thought of subclassing the Dictionary<string,YourObject> ?
For what you are asking two are the simplest ways i see based on what i have understood.
You can use a general function with parameter object or a common base object like BaseMemeberShip for all possible MemberShip objects to be added. Then by using the is Address for example determine to which dictionary you will add it. You can also use GetType()
A second way which probably is the same from the functional scope, is to implement an interface which somehow signals what kind of Membership Object it is you are adding.
|
|
|
|
|
Hi
thanks for the reply. But I dont get what you are saying, either i mis-interpret or u misunderstood my meaning.
I guess what im getting at is for this function
public T GetObjectByKey<T>(long key)<br />
{<br />
Type t = typeof(T);<br />
}
I hope that makes sense....
|
|
|
|
|
HOW CAN I OPEN OPENDIALOG IN CLIENT-SIDE AND LIST FILES AND DIRECTORIES IN CLIENT-SIDE?
ALA QUNAIBI
|
|
|
|
|
DON'T SHOUT !!!
In ASP.NET 2.0, there's a control for this. In 1.1, I believe you had to use the old HTML file input tag.
This belongs in the ASp.NET forum, really.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
Using .Net 2.0
I have created webservices inside a project. These services are in a solution on my machine which I am developing.
To reference these services, I use Add Web Reference, webservices in this solution (Because the services are saved in my local machine).
At what stage should I place these webservices in the virtual directory of a webserver?
Should these webservices be developed in a virtual directory on my local machine as opposed to in the local C drive as it is now?
The intension is that others be able to see these webservices as they are being developed.
For an example, from my machine to reference one of the webservices, this is the path I use:
http://localhost:2144/inTest.asmx
does this mean that other developers to reference this webservice should use:
http://MyMachineName:2144/inTest.asmx
??
Thanks
|
|
|
|
|
fmardani wrote: Should these webservices be developed in a virtual directory on my local machine as opposed to in the local C drive as it is now?
A webservice will always be on your hard drive, it will simply be in a directory that is mapped to a folder in IIS. VS.NET is mapping it for you, it has a web server built in. You should probably leave it where it is, so you can debug it and work on it. Deploy it when you move it to a machine it will run on.
fmardani wrote: does this mean that other developers to reference this webservice should use:
They should probably reference it locally on their machines. If you want it somewhere that people can run it, but not work on it, then you may want to set up a machine to host it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Is there any code for automatic generation of a password.
thnaks
|
|
|
|
|
I haven't seen one but it can't be that hard to create a function that takes a random number and returns a char based on the ascii values you allow.
I think System.Convert.ToChar(int) is probably the function you need from the top of my head.
Russell
|
|
|
|
|
arachnoid wrote: I think System.Convert.ToChar(int) is probably the function you need from the top of my head.
Use it with Math.Random, but you'll end up having a senseless password!!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
i was thinking that that was the critical function rather than using that as the whole algorithm.
Then create a wrapper that creates a random number between 0 and 61 and returns an lcase, a ucase or a number with equal probability
Russ
|
|
|
|
|
It is like an automatic generation for an activation code.
Maybe my description as a password was some how wronge
|
|
|
|
|
use math.random to create a nuber between 0 and 61
use a switch statement for 0 to 25, 26 to 51, 52 to 61
convert the numbers to letters or numbers using system.convert.tochar(int) and these values ^
loop to create a pwd of required length
HTH
Russ
|
|
|
|
|
Create a char array with all the 'allowed characters'
Call up a random number between 0 and the length of that array for the amount of characters the password should contain.
V.
I found a living worth working for, but haven't found work worth living for.
|
|
|
|
|
|
I think the biggest problem a lot of password generating programs have is that they don't guarantee a strong password. While choosing random characters from a set of predifined values might get you very diversive password, it doesn't mean it always will. So despite using long password, you could still end up with weak ones like 'ifdhgkfsd'. There should be some code to check, if teh generated password meets some special requirements, and possibly do some adjustments. A good example for this is the built-in membership provider for ASP.NET 2.0, which requires you to have at least one non-alphanumerical character in your password. Then again it's not a generator tool, it just checks a given password. I don't mean to stay you need these precautions in every case, however I do mean you should find (or possible write) code that allows usage of similiar features. For example:
public string GetPassword(int length, int minUppercaseLetterCount, int minNumberCount, int minNonAlphanumericalCount)
{
//your code here
}
Obviously, for simple passwords you would use it like GetPassword(5, 0, 0, 0). And if you ever need strong passwords you can still reuse this function.
I think this smells like an article . Someone should write it. Or maybe I will .
|
|
|
|