Click here to Skip to main content
15,893,161 members
Home / Discussions / C#
   

C#

 
QuestionIs it possible to force a using-block for a class? Pin
Uwe Keim5-May-05 20:26
sitebuilderUwe Keim5-May-05 20:26 
AnswerRe: Is it possible to force a using-block for a class? Pin
James T. Johnson5-May-05 21:14
James T. Johnson5-May-05 21:14 
GeneralRe: Is it possible to force a using-block for a class? Pin
Uwe Keim5-May-05 21:27
sitebuilderUwe Keim5-May-05 21:27 
GeneralRe: Is it possible to force a using-block for a class? Pin
Nish Nishant6-May-05 0:06
sitebuilderNish Nishant6-May-05 0:06 
GeneralRe: Is it possible to force a using-block for a class? Pin
Uwe Keim6-May-05 1:05
sitebuilderUwe Keim6-May-05 1:05 
GeneralRe: Is it possible to force a using-block for a class? Pin
Nish Nishant6-May-05 2:16
sitebuilderNish Nishant6-May-05 2:16 
GeneralRe: Is it possible to force a using-block for a class? Pin
S. Senthil Kumar6-May-05 4:55
S. Senthil Kumar6-May-05 4:55 
GeneralConverting Objects Pin
cab35-May-05 19:49
cab35-May-05 19:49 
I am having a problem converting an object. I am new to C# with a C++ background. I modified some sample code to gain some experience with classes and the associative array. My goal is to create my custom class and use the associative array to house instances of that class. Most examples show how to view the data with the console.writeline method (works for me also), but I would like to place the information in a local field at the main level.

I can store various instances into the array and view them in the debugger, but I cannot access them through main as show below. I get the following error message: Cannot implicitly convert type 'object' to 'ConsoleApplication4.Checks.

I would really appreciate some help.

Thanks,


public class Checks;
{
  public Checks(int RegisterID, int CatID);
  {
    :
    :
  }
}

public class Register
{
  public Register(int size)
  {
    :
    :
  }
  
  public object this[int RegisterID, int CatID]
  {
   get
      {
      string key = Convert.ToString(RegisterID);
      key += Convert.ToString(CatID);
      return KeyToObject(key);
      }

   set
      {
         :
         :
      }
  }

  protected object KeyToObject(string key)
  {
   for(int n = 0; n < _count; ++n)
          {
           Checks trankey = (Checks)_items[n];
           if(key == trankey.key)
                  return trankey;
           }
   return null;
   }
}

class Class1
{
  static void Main(string[] args)
  {
     Register Pay = new Register (1);
     Checks temp = new Checks (5,3);
     temp.Description = "Vons";
     temp.Amount = 30.50m;
     Register [5,3]= temp;
     temp = new Checks(6,2);
     temp.Description = "Home Depot";
     temp.Amount = 126.75m;
     Register [6,2]= temp;
     temp = Register [5,3];   // throws the error
  }
}


cab3
GeneralRe: Converting Objects Pin
Mathew Hall6-May-05 1:51
Mathew Hall6-May-05 1:51 
GeneralRe: Converting Objects Pin
cab36-May-05 5:32
cab36-May-05 5:32 
Generalusb interfacing using c#.Net Pin
ahsan1415-May-05 19:19
ahsan1415-May-05 19:19 
GeneralRe: usb interfacing using c#.Net Pin
Kayess Tech5-May-05 20:14
professionalKayess Tech5-May-05 20:14 
GeneralTwo problems about image processing in Pocket PC Pin
redleafong5-May-05 18:33
redleafong5-May-05 18:33 
GeneralRe: Two problems about image processing in Pocket PC Pin
Andrew Kirillov5-May-05 18:48
Andrew Kirillov5-May-05 18:48 
Generalclipping video using DirectShow in C# Pin
5-May-05 18:28
suss5-May-05 18:28 
GeneralDataGrid Cell Edit Pin
Kayess Tech5-May-05 18:16
professionalKayess Tech5-May-05 18:16 
GeneralRe: DataGrid Cell Edit Pin
Polis Pilavas6-May-05 0:32
Polis Pilavas6-May-05 0:32 
GeneralRe: DataGrid Cell Edit Pin
Kayess Tech6-May-05 0:34
professionalKayess Tech6-May-05 0:34 
GeneralRe: DataGrid Cell Edit Pin
Polis Pilavas6-May-05 1:15
Polis Pilavas6-May-05 1:15 
GeneralRe: DataGrid Cell Edit Pin
Kayess Tech6-May-05 1:27
professionalKayess Tech6-May-05 1:27 
GeneralRe: DataGrid Cell Edit Pin
Polis Pilavas6-May-05 1:38
Polis Pilavas6-May-05 1:38 
Generalweb service Pin
skrishnasarma5-May-05 17:57
skrishnasarma5-May-05 17:57 
GeneralRe: web service Pin
Dan_P5-May-05 18:29
Dan_P5-May-05 18:29 
GeneralRe: web service Pin
skrishnasarma5-May-05 19:46
skrishnasarma5-May-05 19:46 
GeneralADO.NET Pin
Dharma Dassanayake5-May-05 16:17
Dharma Dassanayake5-May-05 16:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.