Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. maximum number of methods supported in C# class

maximum number of methods supported in C# class

Scheduled Pinned Locked Moved C#
questioncsharp
32 Posts 13 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Sathesh Sakthivel

    vytheeswaran wrote:

    how many methods a single C# class can allow ?

    We can have as we can. For More Details: MSDN[^]

    Regards, Satips.:rose:

    C Offline
    C Offline
    Colin Angus Mackay
    wrote on last edited by
    #4

    Where does that article answer the OP's question? Or did you just chuck some keywords in to Google and hit "I'm feeling lucky"?


    Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." Ready to Give up - Your help will be much appreciated. My website

    1 Reply Last reply
    0
    • S Sathesh Sakthivel

      vytheeswaran wrote:

      how many methods a single C# class can allow ?

      We can have as we can. For More Details: MSDN[^]

      Regards, Satips.:rose:

      V Offline
      V Offline
      vytheese
      wrote on last edited by
      #5

      Thanks for Info, But I read in one article that E-Bay once hits the compiler limit in max number of methods in single class. Thanks, Vythees

      D 1 Reply Last reply
      0
      • V vytheese

        Just curiosity ;) , Did anyone have idea of how many methods a single C# class can allow ? I heard, it is compiler dependent If true, what is the maximum no allowed by the standard compiler ? Thanks, Vythees

        M Offline
        M Offline
        martin_hughes
        wrote on last edited by
        #6

        I just had a search through MS's C# Comiler errors/warnings list http://msdn2.microsoft.com/en-us/library/ms228373(VS.80).aspx[^] and can't see anything that explicitly complains about too many methods being in a class.

        1 Reply Last reply
        0
        • V vytheese

          Just curiosity ;) , Did anyone have idea of how many methods a single C# class can allow ? I heard, it is compiler dependent If true, what is the maximum no allowed by the standard compiler ? Thanks, Vythees

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #7

          Seeing Assembly metatokens takes the following form: 00 000000, where the former is the type, and the latter is the code, I would say the maximum number of methoddef's in an assembly would be limited to 24-bits, iow 16.7 million. Dunno if there is a limitation on a classes though.

          **

          xacc.ide-0.2.0.75 - now with C# 3.5 support and Navigation Bar!

          **

          V E 2 Replies Last reply
          0
          • V vytheese

            Just curiosity ;) , Did anyone have idea of how many methods a single C# class can allow ? I heard, it is compiler dependent If true, what is the maximum no allowed by the standard compiler ? Thanks, Vythees

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #8

            when in trouble, switch to Win64. :)

            Luc Pattyn [My Articles] [Forum Guidelines]

            V 1 Reply Last reply
            0
            • C Colin Angus Mackay

              vytheeswaran wrote:

              Did anyone have idea of how many methods a single C# class can allow ?

              I think that if you ever reached that limit then you might want to seriously reconsider your design.


              Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." Ready to Give up - Your help will be much appreciated. My website

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #9

              Colin Angus Mackay wrote:

              I think that if you ever reached that limit then you might want to seriously reconsider your design.

              or the switch/case limit or the if/elseif limit or the .... or if none of that makes sense to you try this[^]

              V 1 Reply Last reply
              0
              • L leppie

                Seeing Assembly metatokens takes the following form: 00 000000, where the former is the type, and the latter is the code, I would say the maximum number of methoddef's in an assembly would be limited to 24-bits, iow 16.7 million. Dunno if there is a limitation on a classes though.

                **

                xacc.ide-0.2.0.75 - now with C# 3.5 support and Navigation Bar!

                **

                V Offline
                V Offline
                vytheese
                wrote on last edited by
                #10

                A nice research. Thanks, Vythees

                L 1 Reply Last reply
                0
                • V vytheese

                  Thanks for Info, But I read in one article that E-Bay once hits the compiler limit in max number of methods in single class. Thanks, Vythees

                  D Offline
                  D Offline
                  Dan Neely
                  wrote on last edited by
                  #11

                  IIRC ebay is running its servers using c++ and ISAPI, not .net.

                  -- You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer

                  V 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    when in trouble, switch to Win64. :)

                    Luc Pattyn [My Articles] [Forum Guidelines]

                    V Offline
                    V Offline
                    vytheese
                    wrote on last edited by
                    #12

                    Fiction : :) I may end up with Portablity issues with 32bit cousins. Not an real issue, but just to know the number. :wtf: Thanks, Vythees

                    1 Reply Last reply
                    0
                    • D Dan Neely

                      IIRC ebay is running its servers using c++ and ISAPI, not .net.

                      -- You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer

                      V Offline
                      V Offline
                      vytheese
                      wrote on last edited by
                      #13

                      I agree, I think then there should be the same constraint exist in .NET class also. Thanks, Vythees

                      D 1 Reply Last reply
                      0
                      • L led mike

                        Colin Angus Mackay wrote:

                        I think that if you ever reached that limit then you might want to seriously reconsider your design.

                        or the switch/case limit or the if/elseif limit or the .... or if none of that makes sense to you try this[^]

                        V Offline
                        V Offline
                        vytheese
                        wrote on last edited by
                        #14

                        Oh God, thats classic link. :) Thanks, Vythees

                        1 Reply Last reply
                        0
                        • L leppie

                          Seeing Assembly metatokens takes the following form: 00 000000, where the former is the type, and the latter is the code, I would say the maximum number of methoddef's in an assembly would be limited to 24-bits, iow 16.7 million. Dunno if there is a limitation on a classes though.

                          **

                          xacc.ide-0.2.0.75 - now with C# 3.5 support and Navigation Bar!

                          **

                          E Offline
                          E Offline
                          Ed Poore
                          wrote on last edited by
                          #15

                          There is a limit, I remember someone a while ago (I've got a feeling in this forum) hit a limit on the number of fields in anycase that they could include in a class.  Buggered if I can remember where it was or what it was :sigh:


                          My Blog

                          L 1 Reply Last reply
                          0
                          • V vytheese

                            A nice research. Thanks, Vythees

                            L Offline
                            L Offline
                            leppie
                            wrote on last edited by
                            #16

                            Not research, I know it from working with the spec :) And those values can be accessed from .NET 2 (nowadays).

                            **

                            xacc.ide-0.2.0.75 - now with C# 3.5 support and Navigation Bar!

                            **

                            1 Reply Last reply
                            0
                            • E Ed Poore

                              There is a limit, I remember someone a while ago (I've got a feeling in this forum) hit a limit on the number of fields in anycase that they could include in a class.  Buggered if I can remember where it was or what it was :sigh:


                              My Blog

                              L Offline
                              L Offline
                              leppie
                              wrote on last edited by
                              #17

                              Maybe you are thinking about the parameter limit, that is 16383/4.

                              **

                              xacc.ide-0.2.0.75 - now with C# 3.5 support and Navigation Bar!

                              **

                              E 1 Reply Last reply
                              0
                              • L leppie

                                Maybe you are thinking about the parameter limit, that is 16383/4.

                                **

                                xacc.ide-0.2.0.75 - now with C# 3.5 support and Navigation Bar!

                                **

                                E Offline
                                E Offline
                                Ed Poore
                                wrote on last edited by
                                #18

                                No, I'm pretty sure that someone managed to hit a limit on the number of fields that could be contained in a class.  I'll do some digging.


                                My Blog

                                1 Reply Last reply
                                0
                                • V vytheese

                                  Just curiosity ;) , Did anyone have idea of how many methods a single C# class can allow ? I heard, it is compiler dependent If true, what is the maximum no allowed by the standard compiler ? Thanks, Vythees

                                  S Offline
                                  S Offline
                                  Sean Michael Murphy
                                  wrote on last edited by
                                  #19

                                  I let this run for an hour to get to 5000 before I gave up. Someone with more CPU and physical RAM than I have should run it and see where it ends...

                                  using System;
                                  using System.Collections.Generic;
                                  using System.Text;
                                  using System.CodeDom.Compiler;
                                     
                                  namespace MethodCountLimitFinder {
                                     class Program {
                                        static void Main(string[] args) {
                                           Int32 methodCount = 1;
                                           Microsoft.CSharp.CSharpCodeProvider cscp = new Microsoft.CSharp.CSharpCodeProvider();
                                           ICodeCompiler icc = cscp.CreateCompiler();
                                     
                                           CompilerParameters cp = new CompilerParameters();
                                           cp.GenerateExecutable = false;
                                           cp.GenerateInMemory = true;
                                     
                                           CompilerResults cr = null;
                                           string pre = "using System;" + Environment.NewLine +
                                                    Environment.NewLine +
                                                    "namespace Tester {" + Environment.NewLine +
                                                    " class Test {" + Environment.NewLine;
                                           string post = " }" + Environment.NewLine +
                                                    "}";
                                           string inner = string.Empty;
                                     
                                           while (true) {
                                              inner += " public Int32 Method" + methodCount.ToString() + "() {" + Environment.NewLine +
                                                       " return 42;" + Environment.NewLine +
                                                       " }" + Envi

                                  D P 2 Replies Last reply
                                  0
                                  • S Sean Michael Murphy

                                    I let this run for an hour to get to 5000 before I gave up. Someone with more CPU and physical RAM than I have should run it and see where it ends...

                                    using System;
                                    using System.Collections.Generic;
                                    using System.Text;
                                    using System.CodeDom.Compiler;
                                       
                                    namespace MethodCountLimitFinder {
                                       class Program {
                                          static void Main(string[] args) {
                                             Int32 methodCount = 1;
                                             Microsoft.CSharp.CSharpCodeProvider cscp = new Microsoft.CSharp.CSharpCodeProvider();
                                             ICodeCompiler icc = cscp.CreateCompiler();
                                       
                                             CompilerParameters cp = new CompilerParameters();
                                             cp.GenerateExecutable = false;
                                             cp.GenerateInMemory = true;
                                       
                                             CompilerResults cr = null;
                                             string pre = "using System;" + Environment.NewLine +
                                                      Environment.NewLine +
                                                      "namespace Tester {" + Environment.NewLine +
                                                      " class Test {" + Environment.NewLine;
                                             string post = " }" + Environment.NewLine +
                                                      "}";
                                             string inner = string.Empty;
                                       
                                             while (true) {
                                                inner += " public Int32 Method" + methodCount.ToString() + "() {" + Environment.NewLine +
                                                         " return 42;" + Environment.NewLine +
                                                         " }" + Envi

                                    D Offline
                                    D Offline
                                    DavidNohejl
                                    wrote on last edited by
                                    #20

                                    Sean Michael Murphy wrote:

                                    while (true) { inner += " public Int32 Method" + methodCount.ToString() + "() {" + Environment.NewLine + " return 42;" + Environment.NewLine + " }" + Environment.NewLine; cr = icc.CompileAssemblyFromSource(cp, pre + inner + post); if (cr.Errors.Count > 0) break; methodCount++; if (methodCount % 10 == 0) System.Console.WriteLine(methodCount.ToString()); }

                                    Sean Michael Murphy wrote:

                                    Someone with more CPU and physical RAM than I have should run it and see where it ends...

                                    No wonder, always use StringBuilder for string concatenation in a loop.


                                    "Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

                                    M S 2 Replies Last reply
                                    0
                                    • V vytheese

                                      I agree, I think then there should be the same constraint exist in .NET class also. Thanks, Vythees

                                      D Offline
                                      D Offline
                                      Dan Neely
                                      wrote on last edited by
                                      #21

                                      Even assuming there is a constraint, you're talking about 2 totally different languages so why should they be the same?

                                      -- You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer

                                      1 Reply Last reply
                                      0
                                      • D DavidNohejl

                                        Sean Michael Murphy wrote:

                                        while (true) { inner += " public Int32 Method" + methodCount.ToString() + "() {" + Environment.NewLine + " return 42;" + Environment.NewLine + " }" + Environment.NewLine; cr = icc.CompileAssemblyFromSource(cp, pre + inner + post); if (cr.Errors.Count > 0) break; methodCount++; if (methodCount % 10 == 0) System.Console.WriteLine(methodCount.ToString()); }

                                        Sean Michael Murphy wrote:

                                        Someone with more CPU and physical RAM than I have should run it and see where it ends...

                                        No wonder, always use StringBuilder for string concatenation in a loop.


                                        "Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

                                        M Offline
                                        M Offline
                                        Martin 0
                                        wrote on last edited by
                                        #22

                                        Cannot been said to often! Good answere!

                                        P 1 Reply Last reply
                                        0
                                        • M Martin 0

                                          Cannot been said to often! Good answere!

                                          P Offline
                                          P Offline
                                          PIEBALDconsult
                                          wrote on last edited by
                                          #23

                                          Well it can be said too often, but it's appropriate here.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups