471,350 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

how can i turn this java method to c#

public String generateSP()
{
String s = "";
Iterator iterator = hmTable.keySet().iterator();
String s1 = "";
while(iterator.hasNext())
{
String s2 = (String)iterator.next();
s = s.length() != 0 ? s + "," + s2 : s2;
}
return s;
}
thx!

Jan 4 '06 #1
5 1236
The var s1 appears never used?
C#:
public String generateSP()
{
String s = null;
foreach (String s2 in hmTable.Keys)
{
s = (s != null) ? (s + "," + s2) : s2;
}
return s;
}

Due to some error, I have to post twice. Sorry if it this reply appears
twice.

Regards,
Thi

Jan 4 '06 #2
Thx Truong Hong Thi

another ques.
dose c# has some type like java type Vector (java.util.Vector)
?

:)

Jan 4 '06 #3
C# System.Collections.ArrayList provide similar functions, but is is
not thread-safe by default. To have thread-safe array list like
java.util.Vector, use ArrayList.Synchronized method:

ArrayList theVector = ArrayList.Synchronized(new ArrayList);

Hope that helps,
Thi

Jan 4 '06 #4
Truong Hong Thi wrote:
C# System.Collections.ArrayList provide similar functions, but is is
not thread-safe by default. To have thread-safe array list like
java.util.Vector, use ArrayList.Synchronized method:

ArrayList theVector = ArrayList.Synchronized(new ArrayList);


However, that model of thread-safety is pretty shallow anyway - you
can't safely iterate through a synchronized ArrayList (or Vector in
Java) without locking for the whole loop rather than just each bit of
the loop.

Personally I usually avoid the synchronized wrappers, explicitly
locking the SyncRoot property (or a private lock) if a collection needs
to be shared between threads.

Jon

Jan 4 '06 #5
thx Jon Skeet and Truong Hong Thi

:)

Jan 5 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by James Hong | last post: by
reply views Thread by Ravi Tallury | last post: by
12 posts views Thread by Mark Fink | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.