metaclass: (Default)
[personal profile] metaclass
А дайте кто-нибудь примеров, где сабж вызывает проблемы с типами переменных?
А то я идею примерно понимаю, периодически натыкаюсь на проблемы у себя в дотнетах, но не могу составить общую картину в голове, чтобы понять, что именно вызывает проблемы - то ли я с архитектурой фигню сделал, то ли это теоретически неразрешимая проблема и нужно делать обходные костыли.

Date: 2010-01-25 07:23 pm (UTC)
From: [identity profile] rssh.livejournal.com
ее отсуствие или присутствие ?
Отсуствие - понятно, ну к примеру вот недавняя проблема:
http://community.livejournal.com/ru_scala/9444.html

Присутствие - тут не понимаю как использованети может породить проблемв. Ну контрвариантность неочевидна, но это же если используешь, как и любая фича.


микрософтовский сэмпл:

Date: 2010-01-25 07:27 pm (UTC)
From: [identity profile] ko444evnik.livejournal.com
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleVariance
{
class Animal { }
class Cat: Animal { }

class Program
{
// To understand what the new CoVariance and ContraVariance code does for you
// Try deleting or adding the words out and in from the following 2 lines of code:
delegate T Func1();
delegate void Action1(T a);

static void Main(string[] args)
{
Func1 cat = () => new Cat();
Func1 animal = cat;

Action1 act1 = (ani) => { Console.WriteLine(ani); };
Action1 cat1 = act1;

Console.WriteLine(animal());
cat1(new Cat());
}
}
}

Profile

metaclass: (Default)
metaclass

April 2017

S M T W T F S
      1
2345678
9101112 131415
16171819202122
23242526272829
30      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 10th, 2025 04:41 am
Powered by Dreamwidth Studios