我的项目里边真的没有program.cs文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我的项目里边真的没有program.cs文件相关的知识,希望对你有一定的参考价值。

我的知道继续追问,点击下来就没有反应,我只好重新一个问题这样问你,我的项目里边真的没有program.cs文件,我搜索了也一个个看了,真的没有。

那这样,你在VS2005里打开你的那个项目,然后,按Ctrl+F,寻找main。这样就能找到了,
记得查找范围为当前项目。来自:求助得到的回答
参考技术A 估计这个项目的输出类型是类库

csharp 二进制序列化示例(Program.cs + Employee.cs)=两个文件

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace Serialization__Binary__Ex1
{
    class Program
    {
        static void Main(string[] args)
        {
            ////Create a new Employee object
            Employee emp = new Employee();
            emp.EmpId = 62;
            emp.EmpName = "Kawser";

            
            ///* Serialize the object to a sample file */
            //// Open a file and serialize the object into it in binary format.
            //// EmployeeInfo.osl is the file that we are creating. 
            //// Note:- you can give any extension you want for your file
            //// If you use custom extensions, then the user will know 
            //// that the file is associated with your program.
            Stream stream1 = File.Open("EmployeeInfo.osl", FileMode.Create);
            BinaryFormatter bformatter = new BinaryFormatter();

            Console.WriteLine("Writing Employee Information");
            bformatter.Serialize(stream1, emp);
            stream1.Close();




            /*Deserialize the values by reading it from the file */
            //Clear mp for further usage.

            //Open the file written above and read values from it.
            Stream stream2 = File.Open("EmployeeInfo.osl", FileMode.Open);
            BinaryFormatter bformatter2 = new BinaryFormatter();

            Console.WriteLine("Reading Employee Information");
            Employee emp2 = (Employee) bformatter2.Deserialize(stream2);
            stream2.Close();

            Console.WriteLine("Employee Id: {0}", emp2.EmpId.ToString());
            Console.WriteLine("Employee Name: {0}", emp2.EmpName);
            Console.Read();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Serialization__Binary__Ex1
{
    [Serializable()]    //Set this attribute to all the classes that want to serialize
    public class Employee : ISerializable //derive your class from ISerializable
    {
        public int EmpId;
        public string EmpName;
        
        //Default constructor
        public Employee()
        {
            EmpId = 0;
            EmpName = null;
        }
       
        
        //Serialization function.
        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            //You can use any custom name for your name-value pair. But make sure you
            // read the values with the same name. For ex:- If you write EmpId as "EmployeeId"
            // then you should read the same with "EmployeeId"
            info.AddValue("EmployeeId", EmpId);
            info.AddValue("EmployeeName", EmpName);
        }

        //Deserialization constructor.
        public Employee(SerializationInfo info, StreamingContext ctxt)
        {
            //Get the values from info and assign them to the appropriate properties
            EmpId = (int)info.GetValue("EmployeeId", typeof(int));
            EmpName = (String)info.GetValue("EmployeeName", typeof(string));
        }
    }
}

以上是关于我的项目里边真的没有program.cs文件的主要内容,如果未能解决你的问题,请参考以下文章

WPF从program.cs启动项目时报错

从 .net 6 的代码覆盖范围中排除 Program.cs [重复]

C# 为啥我的 RegEx 不匹配?这个真的很简单

探索Asp net core3中的 项目文件Program.cs和通用host(译)

如何在 .NET 6 最小 API Program.cs 中访问 DbContext

如何仅在 .NET 6 Program.cs 中添加配置?