Browse Source

'C#语法学习'

liaolijun 5 tháng trước cách đây
mục cha
commit
6b607f503b

BIN
ConsoleApp2/.vs/ConsoleApp2/v16/.suo


+ 25 - 0
ConsoleApp2/ConsoleApp2.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.36227.6
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp2", "ConsoleApp2\ConsoleApp2.csproj", "{55712A96-C581-4703-AD47-64F6F0D8038C}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{55712A96-C581-4703-AD47-64F6F0D8038C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{55712A96-C581-4703-AD47-64F6F0D8038C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{55712A96-C581-4703-AD47-64F6F0D8038C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{55712A96-C581-4703-AD47-64F6F0D8038C}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {E1861DCF-252E-44FA-9C3C-6EC392DC7F1D}
+	EndGlobalSection
+EndGlobal

+ 44 - 0
ConsoleApp2/ConsoleApp2/Animal.cs

@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConsoleApp2
+{
+    class Animal
+    {
+        public virtual void sound()
+        {
+            Console.WriteLine("make a sound.....");
+        }
+    }
+    class Dog : Animal
+    {
+        public override void sound()
+        {
+            base.sound();
+            Console.WriteLine("wangwangwang......");
+        }
+    }
+    interface sound
+    {
+        void makeSound();
+    }
+    interface eat
+    {
+        void food();
+    }
+    class Cat : sound,eat
+    {
+        public void makeSound()
+        {
+            Console.WriteLine("miaomiaomiao.....");
+        }
+        public void food()
+        {
+            Console.WriteLine("eat cat food...");
+        }
+
+    }
+}

+ 6 - 0
ConsoleApp2/ConsoleApp2/App.config

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
+    </startup>
+</configuration>

+ 26 - 0
ConsoleApp2/ConsoleApp2/Car.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConsoleApp2
+{
+    class Car
+    {
+        public string color = "red";
+        int speed = 200;
+        string name;
+        public Car(string name)
+        {
+            this.name = name;
+            Console.WriteLine("my name is " + this.name);
+        }
+        public void print1()
+        {
+            Console.WriteLine("the car is " + this.color + " and its speed is " + this.speed);
+        }
+    }
+}
+
+

+ 56 - 0
ConsoleApp2/ConsoleApp2/ConsoleApp2.csproj

@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{55712A96-C581-4703-AD47-64F6F0D8038C}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>ConsoleApp2</RootNamespace>
+    <AssemblyName>ConsoleApp2</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+    <Deterministic>true</Deterministic>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Animal.cs" />
+    <Compile Include="Car.cs" />
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Student.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 48 - 0
ConsoleApp2/ConsoleApp2/Program.cs

@@ -0,0 +1,48 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConsoleApp2
+{
+    class Program
+    {
+        static void MyMethod(string name1,string name2)
+        {
+            Console.WriteLine("I am "+name1);
+            Console.WriteLine("I am "+name2);
+        }
+        static void Main(string[] args)
+        {
+            int[,] arr = { { 1, 2, 3 }, { 4, 5,6 } };
+            for(int i = 0; i < arr.GetLength(0); i++)
+            {
+                for(int j = 0; j < arr.GetLength(1); j++)
+                {
+                    Console.WriteLine(arr[i,j]);
+                }
+            }
+            MyMethod(name1:"xiaoming",name2:"xiaohong");
+            Car car = new Car("benz");
+            Console.WriteLine("the color of this car is " + car.color);
+            car.print1();
+            Console.WriteLine("------------------------------------------------------------------");
+            Student stu = new Student();
+            stu.Name = "dahua";
+            Console.WriteLine("the name of stu is " + stu.Name);
+            middleStu stu1 = new middleStu();
+            stu1.Name = "DJH";
+            stu1.print2();
+            Dog dog = new Dog();
+            dog.sound();
+            Console.WriteLine("------------------------------------------------------------------");
+            Cat cat = new Cat();
+            cat.makeSound();
+            cat.food();
+            // 等待用户输入,防止窗口立即关闭
+            Console.WriteLine("按任意键退出...");
+            Console.ReadKey();
+        }
+    }
+}

+ 36 - 0
ConsoleApp2/ConsoleApp2/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("ConsoleApp2")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("HP Inc.")]
+[assembly: AssemblyProduct("ConsoleApp2")]
+[assembly: AssemblyCopyright("Copyright © HP Inc. 2025")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("55712a96-c581-4703-ad47-64f6f0d8038c")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
+//通过使用 "*",如下所示:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 28 - 0
ConsoleApp2/ConsoleApp2/Student.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConsoleApp2
+{
+    class Student
+    {
+        private String name;//字段
+        public String Name//属性
+        {
+            get { return name; }
+            set { name=value; }
+
+        }
+    }
+    class middleStu : Student
+    {
+        public int age = 17;
+        public void print2()
+        {
+            string line=string.Concat(this.Name , " have "  ,age);
+            Console.WriteLine(line);
+        }
+    }
+}

BIN
ConsoleApp2/ConsoleApp2/bin/Debug/ConsoleApp2.exe


+ 6 - 0
ConsoleApp2/ConsoleApp2/bin/Debug/ConsoleApp2.exe.config

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
+    </startup>
+</configuration>

BIN
ConsoleApp2/ConsoleApp2/bin/Debug/ConsoleApp2.pdb


+ 4 - 0
ConsoleApp2/ConsoleApp2/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs

@@ -0,0 +1,4 @@
+// <autogenerated />
+using System;
+using System.Reflection;
+[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]

BIN
ConsoleApp2/ConsoleApp2/obj/Debug/ConsoleApp2.csproj.AssemblyReference.cache


+ 1 - 0
ConsoleApp2/ConsoleApp2/obj/Debug/ConsoleApp2.csproj.CoreCompileInputs.cache

@@ -0,0 +1 @@
+6a85c6698046870033d235ecc1f11d8d45017103

+ 7 - 0
ConsoleApp2/ConsoleApp2/obj/Debug/ConsoleApp2.csproj.FileListAbsolute.txt

@@ -0,0 +1,7 @@
+D:\mavenRepository\ConsoleApp2\ConsoleApp2\bin\Debug\ConsoleApp2.exe.config
+D:\mavenRepository\ConsoleApp2\ConsoleApp2\bin\Debug\ConsoleApp2.exe
+D:\mavenRepository\ConsoleApp2\ConsoleApp2\bin\Debug\ConsoleApp2.pdb
+D:\mavenRepository\ConsoleApp2\ConsoleApp2\obj\Debug\ConsoleApp2.csproj.AssemblyReference.cache
+D:\mavenRepository\ConsoleApp2\ConsoleApp2\obj\Debug\ConsoleApp2.csproj.CoreCompileInputs.cache
+D:\mavenRepository\ConsoleApp2\ConsoleApp2\obj\Debug\ConsoleApp2.exe
+D:\mavenRepository\ConsoleApp2\ConsoleApp2\obj\Debug\ConsoleApp2.pdb

BIN
ConsoleApp2/ConsoleApp2/obj/Debug/ConsoleApp2.exe


BIN
ConsoleApp2/ConsoleApp2/obj/Debug/ConsoleApp2.pdb


BIN
ConsoleApp2/ConsoleApp2/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache