using System
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
Student s1 = new Student(1, "张三", 67, 89, 90)
Student s2 = new Student(2, "李四", 68, 90, 91)
Student s3 = new Student(3, "王五", 69, 89, 92)
Student s4 = new Student(4, "赵六", 70, 92, 93)
Console.WriteLine("输出结果")
s1.disp()s2.disp()s3.disp()s4.disp()
Console.WriteLine("语文平均分:{0}数学平均分:{1}英语平均分:{2}", Student.avg1(), Student.avg2(), Student.avg3())
Console.ReadKey()
}
class Student
{
int no
string name
int deg1
int deg2
int deg3
static int sum1 = 0
static int sum2 = 0
static int sum3 = 0
static int sn = 0
public Student(int n, string na, int d1, int d2, int d3)
{
no = nname = na
deg1 = d1deg2 = d2deg3 = d3
sn++
sum1 += d1
sum2 += d2
sum3 += d3
}
public void disp()
{
Console.WriteLine("学号:{0},姓名:{1},语文:{2},数学:{3},英语:{4},平均分:{5:f}", no, name, deg1, deg2, deg3, (double)(deg1 + deg2 + deg3) / 3)
}
public static double avg1() { return (double)sum1 / sn}
public static double avg2() { return (double)sum2 / sn}
public static double avg3() { return (double)sum3 / sn}
}
}
}
1.打开VS2.点击文件->新建->项目
3.在d出的窗口展开Visual C#(点击前面的那个加号)
4.选择控制台应用程序,在那个d出窗口右上角有一个选择框架版本,可以选择框架版本,一般使用默认的即可,
5.在那个d出窗口的下面可以输入项目名称、项目保存位置、解决方案名称
6.输入完后,点击确定,退出那个窗口
7.那个d出窗口退出后,就出现了代码编辑区域
8.代码文件是program.cs,里面的代码结构是这样的:开头的using就是引入命名空间,因为有些类不一定和你这个程序在同一个命名空间下,需要引入命名空间,namespace这个是命名空间,也就是你这个类的命名空间, class Program,后面的Program是类名,C#的类名和文件名可以不一致(Java要求类名和文件名要一致), static void Main(string[] args)这个就是入口函数,也就是主函数,代码写在这个主函数里面,如果执行的时候一闪而过,可以在代码最后加 Console.ReadLine()或 Console.Read()
9.编辑完成,按F5或点击菜单栏上的绿色箭头(右边有个下拉框,下拉框有Debug,这个你不管),程序就能编译链接然后执行
WPF (Windows Presentation Foundation)是用于创建 Windows 桌面应用程序的框架。WPF 通常用于创建图形用户界面 (GUI) 应用程序,而控制台应用程序则是一种没有 GUI,通过控制台进行输入输出 *** 作的应用程序。不过,WPF 也可以用于创建控制台应用程序。下面是使用 WPF 创建控制台应用程序的基本步骤:
1. 打开 Visual Studio 并选择 “新建项目”,选择 “控制台应用程序”。
2. 在解决方案资源管理器中右键单击项目,选择“添加”并选择“引用”。
3. 在“管理 NuGet 程序包” 对话框中搜索并安装“Microsoft.Windows.SDK.Contracts”。
4. 创建一个名为“App.xaml”的文件,其中应包含以下代码:
```xml
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ConsoleApp.App">
<Application.Resources>
<!-- 添加应用程序资源 -->
</Application.Resources>
</Application>
```
5. 创建一个名为“App.xaml.cs”的文件,其中应包含以下代码:
```csharp
using Microsoft.Extensions.Hosting
namespace ConsoleApp
{
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
Host.CreateDefaultBuilder()
.ConfigureServices(services =>services.AddSingleton<MainWindow>())
.Build()
.Services
.GetRequiredService<MainWindow>()
.Show()
}
}
}
```
6. 创建一个名为“MainWindow.xaml”的文件,其中应包含以下代码:
```xml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
title="MainWindow" Height="350" Width="525">
<!-- 在此添加控件和 UI 元素 -->
</Window>
```
7. 创建一个名为“MainWindow.xaml.cs”的文件,其中应包含以下代码:
```csharp
using System.Windows
namespace ConsoleApp
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent()
}
}
}
```
8. 运行应用程序,您将看到控制台中打印的一些内容,同时还会d出一个空白的窗口。在这个窗口中,您可以添加所需的 UI 元素和代码来处理控制台输入输出等 *** 作。
上述步骤仅提供了创建 WPF 控制台应用程序的基本步骤,具体实现方式可能因应用程序需求而异。您可能需要自行添加一些代码来完成特定的 *** 作。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)