小编Rag*_*v55的帖子

对象序列化

假设对象A有6个字段,现在对象A被序列化,经过一段时间后,再添加3个字段并对对象进行反序列化.

  1. 添加新字段将在反序列化时创建任何异常.
  2. 如何具有向后兼容性

c# object-serialization

3
推荐指数
1
解决办法
531
查看次数

传入参数的名称与字段名称相同

class  Person
{
  public string name;

  public void SetName(string name)
  {
    name = name;
  }
}    

public void static Main(string[] args)
{    
  Person aPerson = new Person();
  aPerson.SetName("ruby");

  Console.WriteLine("person name is {0}}, aPerson.name);
}
Run Code Online (Sandbox Code Playgroud)

这个人的名字是空的.这可以消除使用this.name = name;

人名是空的(空字符串)是什么原因?

c#

3
推荐指数
1
解决办法
1666
查看次数

如果我在C#中的Main方法是私有的,为什么我的程序会工作?

默认情况下,类中每个成员的类型修饰符都是私有的,即使Main()函数类型修饰符是私有的.CLR如何调用外部世界不可见的主要方法?

c# clr

3
推荐指数
1
解决办法
894
查看次数

什么是CPU不可知的意思

这可能是一个基本问题,但CIL的含义是什么?

我知道CIL是一种平台和CPU无关的中间语言,但是有人会解释一些有关这方面的细节以及CPU不可知的含义.

cil

2
推荐指数
1
解决办法
1546
查看次数

委托添加和删除

我写了一个示例,

当我创建一个如下所示的委托实例时

AddFunctions d1 += new AddFunctions(Function1); 
Run Code Online (Sandbox Code Playgroud)

我收到了编译错误,因此删除了+ =并以这种方式创建

AddFunctions d1 = new AddFunctions(Function1);
Run Code Online (Sandbox Code Playgroud)

我只是很想知道,为什么在创建单个委托实例时不允许多播(+ =)?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Delegates
{
    public delegate void AddFunctions();

    class Program
    {

        static void Main(string[] args)
        {
            AddFunctions d1 = new AddFunctions(Function1);
            d1 -= d1;
            d1();
        }

        static void Function1()
        {
        }

        static void Function2()
        {
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# delegates

2
推荐指数
1
解决办法
4541
查看次数

为什么这些字符串不是单独显示的?

在文件中写下person的内容

名字:Abcd

SecondName:Tsfsdfs

为此,我写了一个示例应用程序

namespace BinaryStream
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamWriter binWriter = new StreamWriter(@"c:\happybirthday.txt");
            string name = "Sachin";
            string secondname = "tendulkar";
            string wishes = "happy birthday";

            string firstname = string.Format("FirstName: {0} \n", name);
            binWriter.Write(firstname);
            string sn = string.Format("SecondName: {0} \n", secondname);
            binWriter.Write(sn);
            binWriter.Close();          
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我打开记事本中的内容,字符串不会显示在下一行中这是什么原因?格式部分是否正确?

c# string

2
推荐指数
1
解决办法
1456
查看次数

如何将对象数组转换为列表

可能重复:
将System.Array转换为List

我想将aPersonDataArr转换为list IList<aPersonDataArr> aPerList = ???和viceVersa - 从列表到数组.如何做到这一点,我不愿意使用LINQ.还有其他办法吗?

class PersonData
{
    public string PersonName;
    public int Age;
}
class Program
{
    static void Main(string[] args)
    {
        PersonData[] aPersonDataArr = new PersonData[2];

        for (int i = 0; i < aPersonDataArr.Length; i++)
        {
            aPersonDataArr[i].PersonName = "abcd";
            aPersonDataArr[i].Age = 10;
        }    
    }
}
Run Code Online (Sandbox Code Playgroud)

c#

2
推荐指数
1
解决办法
2万
查看次数

抛出异常时调用其他函数 - C#委托

如果委托指向5个方法,则在调用委托时,在第一个方法中发生重复.因为异常发生,所以无法调用4个函数中的其余函数.如何让代理人在异常幸福的情况下调用其他函数

c#

0
推荐指数
1
解决办法
80
查看次数

C#.net中的浅层和深层克隆

class CloneExample : ICloneable
{
    private int m_data ;
    private double m_data2 ;

    public object Clone()
    {
        return this.MemberwiseClone();
    }

    public CloneExample()
    {

    }

    public CloneExample(int data1, int data2)
    {
        m_data = data1;
        m_data2 = data2;
    }

    public override string ToString()
    {
       return String.Format("[d1,d2] {0} {1}", m_data, m_data2);
    }
}
class Program
{
    static void Main(string[] args)
    {
        CloneExample aEx = new CloneExample(10,20);
        CloneExample aEx2 = (CloneExample)aEx.Clone();

        Console.WriteLine("the first object value is {0}", aEx.ToString());
        Console.WriteLine("the first object value is {0}", …
Run Code Online (Sandbox Code Playgroud)

c#

0
推荐指数
1
解决办法
961
查看次数

在foreach循环中运行for循环

我必须用这种格式写出内容

somename1  value1 value2 value1 value2 ....
somename2  value1 value2 value1 value2 ....
somename3  value1 value2 value1 value2 ....
somename4  value1 value2 value1 value2 ....
somename5  value1 value2 value1 value2 ....
Run Code Online (Sandbox Code Playgroud)

value1和value2是一个点的x和y坐标的一部分,所以为此我创建了一个类:

class Points
{
 string name;
 double[] X;
 double[] Y;
}

class PointsCollection
{
  List<Points> aPoints
}

//now when accessing the PointCollection
foreach(Points aPoints in PointsCollection)
{
   stream.Write(aPoints.Name)
   //now i have to write the value1 and valud2

}

possible code

//now when accessing the PointCollection
foreach(Points aPoints in PointsCollection) …
Run Code Online (Sandbox Code Playgroud)

c#

0
推荐指数
1
解决办法
288
查看次数

标签 统计

c# ×9

cil ×1

clr ×1

delegates ×1

object-serialization ×1

string ×1