Click here to Skip to main content
15,904,346 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi I need to assign values for arrays.
My Model
C#
public partial class TaxInfoTaxFiled
{
    public System.Guid TaxInfoTaxFieldID { get; set; }
    public Nullable<System.Guid> TaxInfoID { get; set; }
    public Nullable<System.Guid> TaxFieldID { get; set; }
    public Nullable<System.Guid> FieldTypeID { get; set; }
    public string FieldValue { get; set; }
}
public partial class TaxField
{
    public System.Guid TaxFieldID { get; set; }
    public string DisplayName { get; set; }
    public string PrintName { get; set; }
}


My ViewModel
public string TinNo { get; set; }
    public string CstNo { get; set; }
    public string ExciseRegNo { get; set; }
    public string PanNo { get; set; }
    public string ServiceTaxNo { get; set; }
    public string CinNo { get; set; }
 
    public List<TaxField> TaxField { get; set; }
    public List<TaxInfoTaxFiled> TaxInfoTaxFiled { get; set; }
}

My Controller
C#
ArrayList Alist = new ArrayList();
 {
     Alist.Add("FD713788-B5AE-49FF-8B2C-F311B9CB0CC4");
     Alist.Add("64B512E7-46AE-4989-A049-A446118099C4");
     Alist.Add("376D45C8-659D-4ACE-B249-CFBF4F231915");
     Alist.Add("59A2449A-C5C6-45B5-AA00-F535D83AD48B");
     Alist.Add("03ADA903-D09A-4F53-8B67-7347A08EDAB1");
     Alist.Add("2F405521-06A0-427C-B9A3-56B8931CFC57");
 }
 
 ArrayList objValue=new ArrayList();
 {
     objValue.Add(viewmodel.TinNo);
     objValue.Add(viewmodel.CstNo);
     objValue.Add(viewmodel.PanNo);
     objValue.Add(viewmodel.CinNo);
     objValue.Add(viewmodel.ExciseRegNo);
     objValue.Add(viewmodel.ServiceTaxNo);
 }
 foreach (var tax in viewmodel.TaxInfoTaxFiled)
 {
      foreach (var i in Alist)
      {
          tax.FieldTypeID = Guid.Parse(i.ToString());
      }
      foreach (var j in objValue)
      {
          tax.FieldValue = j.ToString();       
      }
      db.TaxInfoTaxFiled.Add(tax);
  }

My View

My View Contain Six Fields TinNo, CstNo, PanNo, ServiceTaxNo, CinNo, ExciseRegNo.

I want to change the Controller Code Especially the Arraylist to Array

I need to Assign the array Size to 6 . Is there is possible to use 2 dimensional array. Y im asking like this means I need to calucualte the values in For loop in this format

eg i[0]j[0], i[1]j[1], i[2]j[2], i[3]j[3], i[4]j[4],i[5]j[5], i[6]j[6]

then only I can save all the fields values (TinNo, CstNo, PanNo, ServiceTaxNo, CinNo, ExciseRegNo) in same column in next next row and their id's in TaxFieldID Column.


TaxFieldID FieldValue

FD713788-B5AE-49FF-8B2C-F311B9CB0CC4 TinNo

64B512E7-46AE-4989-A049-A446118099C4 CstNo

same as like I need to save the values in Table for that I need to assign the Array size as 6 and Have to store the default GUID's to that array
eg
a[i]

a[0]=FD713788-B5AE-49FF-8B2C-F311B9CB0CC4

a[1]=64B512E7-46AE-4989-A049-A446118099C4   


eg int a[4]={10,20,30,40}

How to do this and how to assign data type for these default Guid values in array.


Thanks
Posted
Updated 9-Dec-15 0:39am
v4

There are types created for these situations. They are called Dictionary, HashSet and HashTable.

You have a key (GUID) and value (your array). Looping through it, you can combine key and value into final array or keep them separate (as Dictionary object) and use them as needed.
 
Share this answer
 
Comments
Member 12087373 9-Dec-15 7:00am    
How to do that . Pls explain me with one eg or take my code as eg Sinisa Hajnal
Sinisa Hajnal 9-Dec-15 7:19am    
This is not free-code-service. You have the types, you obviously know how to use foreach...all you have to do is read a bit about given types and replace your arrays with one such. Example: Dictionary dict = new Dictionary (you set your types)
dict.Add("GUID", array); // key, value pair

You're done.
Member 12087373 9-Dec-15 7:31am    
I know this is not free code service. I just ask you to elaborate your ans that's it. And thanks for your reply
Sinisa Hajnal 10-Dec-15 2:45am    
I included short example of dictionary call, just so you can see how it is structured. But you really need to read the docs first and see which one fits your situation the most. All three types are different and may or may not fit your situation. After you read up and change the code, ask new question with your new problem.

I will change your code if you want, but I have no time before the weekend.
Member 12087373 10-Dec-15 3:19am    
Ok go ahead and pls chang my code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900