none
method RRS feed

All replies

  • Assuming both classes are under the same namespace and the class to call is public scope then create an instance of the class and call the method

    So if the namespace is WindowsFormsApp1 and a class Operations is also in the same namespace simple use 

    var ops = new Operations();
    var result = ops.Reverse("Karen", "Payne");

    Operations

    public class Operations
    {
        public string Reverse(string firstName, string lastName)
        {
            return $"{lastName} {firstName}";
        }
    }

    If Operations class is in a different namespace e.g. MyNamespace then we need a using statement where you want to access Operations e.g.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.IO;
    using System.Linq;
    using System.Text.RegularExpressions;
    using System.Windows.Forms;
    using MyNamespace;
    
    namespace WindowsFormsApp1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private  void button1_Click(object sender, EventArgs e)
            {
                var ops = new Operations();
                var result = ops.Reverse("Karen", "Payne");
            }
    Same holds true for console projects in regards to proper scope and consideration of namespaces.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Saturday, November 16, 2019 2:52 PM
    Moderator
  • Please fix the title, use lower case and expand your question.

    In fact this is such a basic question, you may find the search box quicker than the new forum question box.

    If you do not fix this post, it will be probably viewed by most as spam.

     

    Regards,
    Pete


    #PEJL
    Got any nice code? If you invest time in coding an elegant, novel or impressive answer on MSDN forums, why not copy it over to TechNet Wiki, for future generations to benefit from! You'll never get archived again, and you could win weekly awards!

    Have you got what it takes to become this month's TechNet Technical Guru? Join a long list of well known community big hitters, show your knowledge and prowess in your favoured technologies!

    Saturday, November 16, 2019 2:55 PM
    Moderator
  • Looks like you were composing as others were slamming Karen! :)

    Not sure if this was a genuine post, but kudos to you for a very thorough reply either way.

     

    Best regards


    Doing my best to keep up with an ever changing world!





    Saturday, November 16, 2019 5:31 PM