c# from a java perspective..am I missing something?

Post » Sun May 13, 2012 10:05 am

So I'm supposed to be filling out a method which should be pretty straight forward, and I know java and c# are basically the same thing so the coding itself isn't my problem.
namespace BigIntArithmetic{  class BigInt  {	public BigInt Next { get; private set; }	public char Digit { get; private set; }  }  class BigIntCalculator  {	public BigInt Add(BigInt left, BigInt right)	{	  // Your code here	}  }}

That's what I'm given and I'm supposed to fill in the Add method. So the adding is pretty straight forward, my problem is that I'm assuming I'm only supposed to add code where it says "//your code here" and there's no constructor for BigInt and the mutators(set methods) are private. So is there something about C# I'm missing because I've been trained in Java, or is the problem wrong somehow, and I need to assume I'm able to write a constructor (or have access to the mutators)?
---
Kyle: I better bring some protection
Jessica: Kyle, you're disgusting
User avatar
matt oneil
 
Posts: 3383
Joined: Tue Oct 09, 2007 12:54 am

Post » Sun May 13, 2012 3:51 pm

Weird. Are you doing a chapter on Reflection or something? As you said, there doesn't appear to be a way to set the property values in a straightforward way. Like I said, you could use Reflection to insert values into the properties, but that seems like a silly solution to a simple problem unless that's the point of the excercise.
User avatar
Liii BLATES
 
Posts: 3423
Joined: Tue Aug 22, 2006 10:41 am

Post » Sun May 13, 2012 5:18 pm

Your two classes are separate and require and instance for each of them to get to the properties. So you would have an instance of BigInt with you would define in your Add method which won't work since you cannot have a space in method names.
User avatar
Jessie Rae Brouillette
 
Posts: 3469
Joined: Mon Dec 11, 2006 9:50 am

Post » Sun May 13, 2012 3:48 am

Your two classes are separate and require and instance for each of them to get to the properties. So you would have an instance of BigInt with you would define in your Add method which won't work since you cannot have a space in method names.
I think the idea is that the instances are being passed into the Add method as arguments. I'm assuming that the code that would create an instance of BigIntCalculator and call the Add method is not included in the sample. Doesn't change the fact that you can't actually get any data into the properties of an instance of the BigInt type without Reflection, though. :biggrin:
User avatar
Lillian Cawfield
 
Posts: 3387
Joined: Thu Nov 30, 2006 6:22 pm


Return to Othor Games