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. Calling a function without an object

Calling a function without an object

Scheduled Pinned Locked Moved C#
csharptoolshelpquestion
14 Posts 3 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.
  • T Tamimi Code

    why you want to cancel the (static) option ??

    When you get mad...THINK twice that the only advice Tamimi - Code

    N Offline
    N Offline
    nasambur
    wrote on last edited by
    #3

    becaus i want to call the function directly as:- ..... func1(); ..... and not as:- ..... className.func1(); ..... as we cal function in C..

    T C 2 Replies Last reply
    0
    • N nasambur

      becaus i want to call the function directly as:- ..... func1(); ..... and not as:- ..... className.func1(); ..... as we cal function in C..

      T Offline
      T Offline
      Tamimi Code
      wrote on last edited by
      #4

      maybe iam wrong, but i don't think that is possible. if you wrote a function on a class A and you want to access it from another class B then you cannot access it regardless class A.

      When you get mad...THINK twice that the only advice Tamimi - Code

      N 1 Reply Last reply
      0
      • T Tamimi Code

        maybe iam wrong, but i don't think that is possible. if you wrote a function on a class A and you want to access it from another class B then you cannot access it regardless class A.

        When you get mad...THINK twice that the only advice Tamimi - Code

        N Offline
        N Offline
        nasambur
        wrote on last edited by
        #5

        anyway thanx for reply.. i hav another doubt.. i want to include a file, similarly as of #include. only i want to copy the code at the position where i call the function IncludeFile().

        T C 2 Replies Last reply
        0
        • N nasambur

          anyway thanx for reply.. i hav another doubt.. i want to include a file, similarly as of #include. only i want to copy the code at the position where i call the function IncludeFile().

          T Offline
          T Offline
          Tamimi Code
          wrote on last edited by
          #6

          could you be more specific, i didn't understand the new question..

          nasambur wrote:

          only i want to copy the code at the position where i call the function IncludeFile().

          this is not a professional way to do it , suppose you that you will use that code again, what will happen ?? you will copy the code again ??

          When you get mad...THINK twice that the only advice Tamimi - Code

          N 1 Reply Last reply
          0
          • T Tamimi Code

            could you be more specific, i didn't understand the new question..

            nasambur wrote:

            only i want to copy the code at the position where i call the function IncludeFile().

            this is not a professional way to do it , suppose you that you will use that code again, what will happen ?? you will copy the code again ??

            When you get mad...THINK twice that the only advice Tamimi - Code

            N Offline
            N Offline
            nasambur
            wrote on last edited by
            #7

            hmm. u r right.. i dont know exactly what happens behind when we use the 'using' in C#. plz explain me..

            T C 2 Replies Last reply
            0
            • N nasambur

              hmm. u r right.. i dont know exactly what happens behind when we use the 'using' in C#. plz explain me..

              T Offline
              T Offline
              Tamimi Code
              wrote on last edited by
              #8

              please Rewrite your question in order to understand your problem.

              When you get mad...THINK twice that the only advice Tamimi - Code

              N 1 Reply Last reply
              0
              • N nasambur

                becaus i want to call the function directly as:- ..... func1(); ..... and not as:- ..... className.func1(); ..... as we cal function in C..

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

                Sorry, but what is the big deal about calling ClassName.Func1()? It is better to package these functions up in to an appropriate set of classes. It provides better logical separation.


                Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

                1 Reply Last reply
                0
                • N nasambur

                  anyway thanx for reply.. i hav another doubt.. i want to include a file, similarly as of #include. only i want to copy the code at the position where i call the function IncludeFile().

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

                  nasambur wrote:

                  i want to include a file, similarly as of #include.

                  C# has no need of that funtionality. If you want to be able to use classes, structs, etc. from other namespaces without having to refer to it fully each time use add the appropriate using directive at the top of the class file. You may also have to add a reference to the appropriate assembly that contains the code. To do this, right-click on the project you wish to add the reference to and select "Add Reference...". The dialog contains various tabs that indicate where the assemby is.


                  Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

                  1 Reply Last reply
                  0
                  • N nasambur

                    hmm. u r right.. i dont know exactly what happens behind when we use the 'using' in C#. plz explain me..

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

                    nasambur wrote:

                    i dont know exactly what happens behind when we use the 'using' in C#. plz explain me..

                    Using can be used in two places. In the context of this conversation you mean the way using is used as a directive to import namespaces into the current code file. Using allows the developer to call the class name on its own rather than be forced to use its full name. e.g.

                    using System.Data.SqlClient;
                    ...
                    SqlConnection connection = new SqlConnection();

                    or

                    System.Data.SqlClient.SqlConnection = new System.Data.SqlClient.SqlConnection();


                    Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

                    N 1 Reply Last reply
                    0
                    • T Tamimi Code

                      please Rewrite your question in order to understand your problem.

                      When you get mad...THINK twice that the only advice Tamimi - Code

                      N Offline
                      N Offline
                      nasambur
                      wrote on last edited by
                      #12

                      Actually, we are developing an application to test the User Load for any Website.. below is the script of our tool that loads virtual user and tests the site.. using System; using RTGWebLoad; namespace Coolgoose { public class Transaction { private string username; private string password; public void TransactionMain(RTGHttpBrowser wlHttp, string ThreadNum, long RoundNum, long MaxRounds) { wlHttp.BeginTransaction("Coolgoose_SendingMail"); CallCoolGooseSendMail(wlHttp, ThreadNum, RoundNum, MaxRounds); wlHttp.EndTransaction("Coolgoose_SendingMail"); } public void CallCoolGooseSendMail(RTGHttpBrowser wlHttp, string ThreadNum, long RoundNum, long MaxRounds) { if (RoundNum == 1) CGLogin(wlHttp); CGSM(wlHttp); //if (RoundNum % MaxRounds == 0) // CGLogout(wlHttp); } public void CGLogin(RTGHttpBrowser wlHttp) { string[] loginData = wlHttp.GetData("http://10.80.4.43/?get=userpass", ','); username = loginData[0]; password = loginData[1]; //username = "rtguser"; //password = "rtguser"; wlHttp.Get("http://www.cooltoad.com"); //wlHttp.CheckString("RTGian"); wlHttp.InfoMessage("Page1: " + wlHttp.wlSource); wlHttp.Get("http://www.cooltoad.com/go/email"); wlHttp.Get("http://www.cooltoad.com/account/login.php?mail=1"); wlHttp.ContentType = "application/x-www-form-urlencoded"; wlHttp.FormData("ACCOUNT", username); wlHttp.FormData("PASSWORD", password); wlHttp.Post("http://www.cooltoad.com/account/login.php?mail=1"); //bool bFlag = wlHttp.CheckString("This site uses frames"); // check string //wlHttp.InfoMessage(bFlag.ToString()); wlHttp.Get("http://www.cooltoad.com/common/header_email.php"); wlHttp.Get("http://as03.cooltoad.com/go/desktop?p=folders"); wlHttp.Get("http://as03.cooltoad.com/go/desktop?o=folder:inbox"); wlHttp.InfoMessage("------" + username + " logged IN ------"); //wlHttp.ErrorMessage("Error in Agenda"); } public void CGSM(RTGHttpBrowser wlHttp) { wlHttp.Get("http://as03.cooltoad.com/go/desktop?c=new"); string sCompose = wlHttp.FindString(wlHttp.wlSource, "COMPOSE\" VALUE=\"", "\">"); wlHttp.ContentType = "multipart/form-data"; wlHttp.FormData("TO", "xyz@gmail.

                      C 1 Reply Last reply
                      0
                      • C Colin Angus Mackay

                        nasambur wrote:

                        i dont know exactly what happens behind when we use the 'using' in C#. plz explain me..

                        Using can be used in two places. In the context of this conversation you mean the way using is used as a directive to import namespaces into the current code file. Using allows the developer to call the class name on its own rather than be forced to use its full name. e.g.

                        using System.Data.SqlClient;
                        ...
                        SqlConnection connection = new SqlConnection();

                        or

                        System.Data.SqlClient.SqlConnection = new System.Data.SqlClient.SqlConnection();


                        Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

                        N Offline
                        N Offline
                        nasambur
                        wrote on last edited by
                        #13

                        thanx

                        1 Reply Last reply
                        0
                        • N nasambur

                          Actually, we are developing an application to test the User Load for any Website.. below is the script of our tool that loads virtual user and tests the site.. using System; using RTGWebLoad; namespace Coolgoose { public class Transaction { private string username; private string password; public void TransactionMain(RTGHttpBrowser wlHttp, string ThreadNum, long RoundNum, long MaxRounds) { wlHttp.BeginTransaction("Coolgoose_SendingMail"); CallCoolGooseSendMail(wlHttp, ThreadNum, RoundNum, MaxRounds); wlHttp.EndTransaction("Coolgoose_SendingMail"); } public void CallCoolGooseSendMail(RTGHttpBrowser wlHttp, string ThreadNum, long RoundNum, long MaxRounds) { if (RoundNum == 1) CGLogin(wlHttp); CGSM(wlHttp); //if (RoundNum % MaxRounds == 0) // CGLogout(wlHttp); } public void CGLogin(RTGHttpBrowser wlHttp) { string[] loginData = wlHttp.GetData("http://10.80.4.43/?get=userpass", ','); username = loginData[0]; password = loginData[1]; //username = "rtguser"; //password = "rtguser"; wlHttp.Get("http://www.cooltoad.com"); //wlHttp.CheckString("RTGian"); wlHttp.InfoMessage("Page1: " + wlHttp.wlSource); wlHttp.Get("http://www.cooltoad.com/go/email"); wlHttp.Get("http://www.cooltoad.com/account/login.php?mail=1"); wlHttp.ContentType = "application/x-www-form-urlencoded"; wlHttp.FormData("ACCOUNT", username); wlHttp.FormData("PASSWORD", password); wlHttp.Post("http://www.cooltoad.com/account/login.php?mail=1"); //bool bFlag = wlHttp.CheckString("This site uses frames"); // check string //wlHttp.InfoMessage(bFlag.ToString()); wlHttp.Get("http://www.cooltoad.com/common/header_email.php"); wlHttp.Get("http://as03.cooltoad.com/go/desktop?p=folders"); wlHttp.Get("http://as03.cooltoad.com/go/desktop?o=folder:inbox"); wlHttp.InfoMessage("------" + username + " logged IN ------"); //wlHttp.ErrorMessage("Error in Agenda"); } public void CGSM(RTGHttpBrowser wlHttp) { wlHttp.Get("http://as03.cooltoad.com/go/desktop?c=new"); string sCompose = wlHttp.FindString(wlHttp.wlSource, "COMPOSE\" VALUE=\"", "\">"); wlHttp.ContentType = "multipart/form-data"; wlHttp.FormData("TO", "xyz@gmail.

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

                          Your mate is thinking the wrong way for C#. You can wrap this code in to a class library of its own. Then you can reference the class library from where it is needed, if it is needed in multiple projects.


                          Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

                          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