0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

.NET4から.NET3.5のDLLを参照したときの挙動

Posted at

構成

■プロジェクト1
対象のプラットフォーム:.NET Framework4
出力の種類:Windowsアプリケーション
プロジェクト2を参照設定する(プロジェクト2のDLLを参照しても結果は同じ)
■プロジェクト2
対象のプラットフォーム:.NET Framework3.5
出力の種類:クラスライブラリ

最初の想定

プロジェクト1では.NET4として動作し、プロジェクト2では.NET3.5として動作する。

検証

ハイフンに対するstring.IndexOfの挙動が.NET4と.NET3.5で異なるのでこれを使ってみた。

サンプル
string text = "\xAD\x2D";
int ret = text.IndexOf(text);
MessageBox.Show(ret.ToString());

上記を実行すると、.NET4の場合「1」が表示され、.NET3.5の場合「0」が表示される。

プロジェクト1namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var obj = new ClassLibrary1.Class1();

            string text = "\xAD\x2D";
            int ret = text.IndexOf(text); // ここでは「1」が取得される
            MessageBox.Show(ret.ToString());

            int ret2 = obj.GetIndex();
            MessageBox.Show(ret2.ToString());
        }
    }
}
プロジェクト2
namespace ClassLibrary1
{
    public class Class1
    {
        public int GetIndex()
        {
            string text = "\xAD\x2D";
            int ret = text.IndexOf(text); // ここでは「0」が取得されると思っていたが「1」が取得される
            return ret;
        }
    }
}

こうすれば、メッセージボックスは「1」「0」と表示されると思っていた。
けれども、実際には「1」「1」と表示される。

もちろんプロジェクト1の「対象のプラットフォーム」を「.NET Framework3.5」にすると
「0」「0」と表示される。

なんか壮絶に勘違いしてる模様 orz

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?