2. c#从不同cs的文件调用函数

1.文件目录如下:

  1. Program.cs文件的主函数如下

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace datasAnalysis
    {
    internal static class Program
    {
    ///


    /// 应用程序的主入口点
    ///

    [STAThread]
    static void Main()
    {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
    }
    }
    }

3.Form1.cs文件的代码如下:

复制代码
using datasAnalysis.analysis;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace datasAnalysis
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            ans ss = new ans();
            ss.outputs();

            txt_r hh = new txt_r();
            hh.outputs();

            for (int i = 0; i < 11; i++)
            {
                Debug.WriteLine(ss.width);
                Debug.WriteLine(hh.high);
            } 
        }
    }
}

以上文件调用了ans文件的outputs函数和txt_1文件的outputs函数。

4.ans.cs文件的代码如下:

复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace datasAnalysis
{
    public partial class ans
    {
        public double width = 10;
        public double outputs()
        {
            return width;
        }

    }
}

5.txt_r.cs文件的代码如下:

复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace datasAnalysis.analysis
{
    public class txt_r
    {

        public double high = 100;
        public double outputs()
        {
            return high;
        }

    }

}

6.代码运行结果如下:

以上就是不同cs文件的函数调用,经过测试运行结果正确无误。

相关推荐
lsswear6 分钟前
Python 并发 线程
开发语言·python
郑州光合科技余经理15 分钟前
国际版外卖系统:税率字段怎么和订单主流程解耦
android·java·开发语言·前端·后端·php·ai编程
软件课代表CiCi31 分钟前
运行库是什么?电脑缺运行库怎么办?c++运行库缺失修复全攻略
开发语言·c++·windows·电脑·dll修复·dll丢失·运行库
Ivanqhz1 小时前
MLIR OpBuilder
开发语言·python·mlir
zxy28472253012 小时前
C# 音频倍速播放
c#·音频·naudio·soundtouch·倍速
红宝村村长2 小时前
windows笔记本双系统ubuntu设置
开发语言
菜鸟~noob2333 小时前
【电子战】第15篇:混合定位——TDOA/FDOA/AOA 联合【含matlab代码】
开发语言·matlab
Dreams_l5 小时前
死信队列和延迟队列介绍
java·开发语言
Water_Sunzhipeng5 小时前
HandyControl Demo 设置特定框架记录
c#
Zenova EdgeOS5 小时前
Python 工业边缘 redis-py 异步实战
开发语言·redis·python