xusword
April 2nd, 2009, 10:55 AM
Hi all
I was a Java programmer, I am used to doing something as followed:
IO Example: (It's not the best example I can come up with, but it is the simplest one)
public interface IO<T>{
T parse(stream s);
String print(T o);
}
public class IOA extends IO<A>{
A parse(stream s){
A instanceA;
// parse A
return instanceA;
}
String print(A a){
return a.toString();
}
}
public class IOB extends IO<B>{
B parse(stream s){
A instanceA;
//parse B
return instanceB;
}
String print(B b){
return b.toString();
}
}
so far, everything can translate to C#
BUT
I cannot find a way to translate the following to C#
public class Peeker{
public Parser<?> peekAndFindSuitableParser(stream s){
// peeking.... then determine
if (/* need to return parserA */...){
return new ParserA();
}
else if (/* need to return parserB */...){
return new ParserB();
}
}
}
Is it possible to translate this to C#?
If not, should I just remove all the generics in these code?
I was a Java programmer, I am used to doing something as followed:
IO Example: (It's not the best example I can come up with, but it is the simplest one)
public interface IO<T>{
T parse(stream s);
String print(T o);
}
public class IOA extends IO<A>{
A parse(stream s){
A instanceA;
// parse A
return instanceA;
}
String print(A a){
return a.toString();
}
}
public class IOB extends IO<B>{
B parse(stream s){
A instanceA;
//parse B
return instanceB;
}
String print(B b){
return b.toString();
}
}
so far, everything can translate to C#
BUT
I cannot find a way to translate the following to C#
public class Peeker{
public Parser<?> peekAndFindSuitableParser(stream s){
// peeking.... then determine
if (/* need to return parserA */...){
return new ParserA();
}
else if (/* need to return parserB */...){
return new ParserB();
}
}
}
Is it possible to translate this to C#?
If not, should I just remove all the generics in these code?