ok guys what im trying here is to fill array with a big integer number(which is string) by using class-objects
first i made two references n1\n2 to the objects entry and arr
-constructor to assign entry to null
i used a property ( as wanted in the question ) to fill them
then i used the pad left to make them from equal length
then i made another constructor to fill the array but its makin an error
the error is not in the compile time but in the run-time :S
can anyone figure out wats going on

namespace Program
   class BigIntegerNumber
      public string entry;
      int[] arr;
      public BigIntegerNumber()
         entry = null;
      public string Fill
            return entry;
            entry = value;
      public BigIntegerNumber(int s)
         arr = new int[s.Length];
         for(int i=0;i<s;i++)
            arr[i] = Convert.ToInt32(entry[i] - 48);
      static void Main(string[] args)
         BigIntegerNumber n1 = new BigIntegerNumber();
         BigIntegerNumber n2 = new BigIntegerNumber();
         Console.Write("Please,Enter the first number :");
         n1.Fill = Console.ReadLine();
         Console.Write("Please,Enter the second number :");
         n2.Fill = Console.ReadLine();
         int local_size;
         if (n1.entry.Length > n2.entry.Length)
            n2.entry = n2.entry.PadLeft(n1.entry.Length, '0');
            local_size = n1.entry.Length;
            n1.entry = n1.entry.PadLeft(n2.entry.Length, '0');
            local_size = n2.entry.Length;
         int s1 = n1.entry.Length;
         int s2 = n2.entry.Length;
         n1 = new BigIntegerNumber(s1);
         n2 = new BigIntegerNumber(s2);

Recommended Answers

All 4 Replies

You didn't mention the actual error, but at first glance, it appears you never allocate your array, arr , before attempting to assign the values inside your constructor. Try allocating it first in the constructor:

arr = new int[s];

I tried it but it didnt work
as I said the problem is a ( run-time error ) so I cant figure wat is it
but its happening in the second constructor

ok sorry for disturbing but I should write

arr[i] = Convert.ToInt32(s[i] - 48);

instead of this

arr[i] = Convert.ToInt32(entry[i] - 48);

You edited your post after I provided a solution to a potential problem, which makes this thread more confusing...

Why did you use s.Length to allocate the array instead of just new int[s] in your constructor? You are looping through "n", or "s" in this case, not the length of an "int"!

Also, include the error message you are getting, which will help narrow down your problem too...

EDIT: You also introduced a new error by trying to access int s as an array in your posted change:

arr[i] = Convert.ToInt32(s[i] - 48);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.