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文件的函数调用,经过测试运行结果正确无误。

相关推荐
ytttr8733 小时前
隐马尔可夫模型(HMM)MATLAB实现范例
开发语言·算法·matlab
天远Date Lab3 小时前
Python实战:对接天远数据手机号码归属地API,实现精准用户分群与本地化运营
大数据·开发语言·python
listhi5203 小时前
基于Gabor纹理特征与K-means聚类的图像分割(Matlab实现)
开发语言·matlab
qq_433776424 小时前
【无标题】
开发语言·php
Davina_yu4 小时前
Windows 下升级 R 语言至最新版
开发语言·windows·r语言
阿珊和她的猫5 小时前
IIFE:JavaScript 中的立即调用函数表达式
开发语言·javascript·状态模式
listhi5205 小时前
卷积码编码和维特比译码的MATLAB仿真程序
开发语言·matlab
yuan199975 小时前
基于主成分分析(PCA)的故障诊断MATLAB仿真
开发语言·matlab
J_liaty5 小时前
Java版本演进:从JDK 8到JDK 21的特性革命与对比分析
java·开发语言·jdk
翔云 OCR API5 小时前
发票查验接口详细接收参数说明-C#语言集成完整示例-API高效财税管理方案
开发语言·c#