Вопросы по с#
От: dub  
Дата: 22.09.06 08:24
Оценка:
Вопросы по с# из теста c BrainBench
При прохождении теста вычмтал несколько интересных вопросов на которые хотел бы узнать правильный ответ
Если кто знает подскажите правильный ответ и почему.
Спасибо.

Вопросы:

--
Within an instance constructor of a struct type, the "this" keyword behaves exactly as an output parameter of the struct type
--
A user-defined conversion is NOT allowed to which of the following types? 
Choice 1   
 "struct" and "array" types  
Choice 2   
 "abstract class" and "object" types  
Choice 3   
 "object" and "interface" types  
Choice 4   
 "struct" and "enum" types  
Choice 5   
 "delegate" and "enum" types




--
internal class Piston {} 

internal class Engine 
{ 
 private Piston[] myPistons = new Piston[4]; 
 public bool Ignition() { 
   // some code... 
   return true; 
 } 
} 

public class Car 
{ 
 private Engine myEngine = new Engine(); 
 public void Start() 
 { 
   // put in keys etc... 
   if (myEngine.Ignition()) { 
     // some more code 
   } 
 } 
}  
  What OO concept does the above sample code demonstrate?  
Choice 1   
 Combination  
Choice 2   
 Inheritance  
Choice 3   
 Composition  
Choice 4   
 Polymorphism  
Choice 5   
 Delegation  
--
Which one of the following describes the OO concept of Aggregation?  
Choice 1   
 A system of objects that define each other  
Choice 2   
 A system of objects that are not related  
Choice 3   
 A system of objects that implement each other  
Choice 4   
 A system of objects inherited from each other  
Choice 5   
 A system of objects that are built using each other



--
Which one of the following variable types is NOT classified as initially assigned?  
Choice 1   
 Value parameters  
Choice 2   
 Instance variables of class instances  
Choice 3   
 Local variables  
Choice 4   
 Static variables  
Choice 5   
 Array elements  
--
Re: Вопросы по с#
От: Сергей Туленцев Россия http://software.tulentsev.com
Дата: 22.09.06 11:35
Оценка: 3 (1) +1
Здравствуйте, dub, Вы писали:

dub>Вопросы по с# из теста c BrainBench

dub>При прохождении теста вычмтал несколько интересных вопросов на которые хотел бы узнать правильный ответ
dub>Если кто знает подскажите правильный ответ и почему.
dub>Спасибо.

dub>Вопросы:


dub>
dub>--
dub>Within an instance constructor of a struct type, the "this" keyword behaves exactly as an output parameter of the struct type
dub>--
А в чем вопрос? :-)

dub>A user-defined conversion is NOT allowed to which of the following types? 
dub>Choice 1   
dub> "struct" and "array" types  
dub>Choice 2   
dub> "abstract class" and "object" types  
dub>Choice 3   
dub> "object" and "interface" types  
dub>Choice 4   
dub> "struct" and "enum" types  
dub>Choice 5   
dub> "delegate" and "enum" types  
dub>


Ответ 3. здесь

dub>
dub>--
dub>internal class Piston {} 

dub>internal class Engine 
dub>{ 
dub> private Piston[] myPistons = new Piston[4]; 
dub> public bool Ignition() { 
dub>   // some code... 
dub>   return true; 
dub> } 
dub>} 

dub>public class Car 
dub>{ 
dub> private Engine myEngine = new Engine(); 
dub> public void Start() 
dub> { 
dub>   // put in keys etc... 
dub>   if (myEngine.Ignition()) { 
dub>     // some more code 
dub>   } 
dub> } 
dub>}  
dub>  What OO concept does the above sample code demonstrate?  
dub>Choice 1   
dub> Combination  
dub>Choice 2   
dub> Inheritance  
dub>Choice 3   
dub> Composition  
dub>Choice 4   
dub> Polymorphism  
dub>Choice 5   
dub> Delegation  
dub>


Composition. Смотреть здесь


dub>
Which one of the following describes the OO concept of Aggregation?  
dub>Choice 1   
dub> A system of objects that define each other  
dub>Choice 2   
dub> A system of objects that are not related  
dub>Choice 3   
dub> A system of objects that implement each other  
dub>Choice 4   
dub> A system of objects inherited from each other  
dub>Choice 5   
dub> A system of objects that are built using each other  
dub>


Ответ 5. Chapter 3 Object-Oriented Concept

dub>
dub>--
dub>Which one of the following variable types is NOT classified as initially assigned?  
dub>Choice 1   
dub> Value parameters  
dub>Choice 2   
dub> Instance variables of class instances  
dub>Choice 3   
dub> Local variables  
dub>Choice 4   
dub> Static variables  
dub>Choice 5   
dub> Array elements  
dub>--
dub>


Локальные переменные.
--
Re: Вопросы по с#
От: cvetkov  
Дата: 22.09.06 12:08
Оценка: 3 (1)
Здравствуйте, dub, Вы писали:
dub>Вопросы:

dub>--
dub>--
dub>A user-defined conversion is NOT allowed to which of the following types? 

dub>


choise 3

dub>--
dub>internal class Piston {} 

dub>internal class Engine 
dub>{ 
dub> private Piston[] myPistons = new Piston[4]; 
dub> public bool Ignition() { 
dub>   // some code... 
dub>   return true; 
dub> } 
dub>} 

dub>public class Car 
dub>{ 
dub> private Engine myEngine = new Engine(); 
dub> public void Start() 
dub> { 
dub>   // put in keys etc... 
dub>   if (myEngine.Ignition()) { 
dub>     // some more code 
dub>   } 
dub> } 
dub>}

choise 3
dub>--
dub>Which one of the following describes the OO concept of Aggregation?  
dub>Choice 1   
dub> A system of objects that define each other  
dub>Choice 2   
dub> A system of objects that are not related  
dub>Choice 3   
dub> A system of objects that implement each other  
dub>Choice 4   
dub> A system of objects inherited from each other  
dub>Choice 5   
dub> A system of objects that are built using each other

choise 5

dub>--
dub>Which one of the following variable types is NOT classified as initially assigned?  
dub>Choice 1   
dub> Value parameters  
dub>Choice 2   
dub> Instance variables of class instances  
dub>Choice 3   
dub> Local variables  
dub>Choice 4   
dub> Static variables  
dub>Choice 5   
dub> Array elements  
dub>--

choise 3
... << RSDN@Home 1.1.4 stable SR1 rev. 568>>
Re[2]: Вопросы по с#
От: dub  
Дата: 22.09.06 12:14
Оценка:
Здравствуйте, Сергей Туленцев, Вы писали:

dub>>[c#]

dub>>--
dub>>Within an instance constructor of a struct type, the "this" keyword behaves exactly as an output parameter of the struct type
dub>>--
СТ>А в чем вопрос?

это утверждение верно? можно примерчик. что то я не пойму как this может быть output parameter?
Re[2]: Вопросы по с#
От: Lloyd Россия  
Дата: 22.09.06 12:15
Оценка: +2 -1
Здравствуйте, cvetkov, Вы писали:

C>
dub>>--
dub>>Which one of the following variable types is NOT classified as initially assigned?  
dub>>Choice 1   
dub>> Value parameters  
dub>>Choice 2   
dub>> Instance variables of class instances  
dub>>Choice 3   
dub>> Local variables  
dub>>Choice 4   
dub>> Static variables  
dub>>Choice 5   
dub>> Array elements  
dub>>--
C>

C>choise 3

Копипаст все-таки иногда рулит.
... << RSDN@Home 1.1.4 stable SR1 rev. 568>>
Re[3]: Вопросы по с#
От: Lloyd Россия  
Дата: 22.09.06 12:17
Оценка:
Здравствуйте, dub, Вы писали:

dub>Здравствуйте, Сергей Туленцев, Вы писали:


dub>>>[c#]

dub>>>--
dub>>>Within an instance constructor of a struct type, the "this" keyword behaves exactly as an output parameter of the struct type
dub>>>--
СТ>>А в чем вопрос?

dub>это утверждение верно? можно примерчик. что то я не пойму как this может быть output parameter?


Там и не написано, что this может быть output-параметром. Написано, что ведет себя в точности как output-параметр.
... << RSDN@Home 1.1.4 stable SR1 rev. 568>>
Re[2]: Вопросы по с#
От: dub  
Дата: 22.09.06 12:22
Оценка:
Здравствуйте, Сергей Туленцев, Вы писали:

dub>>
dub>>--
dub>>Within an instance constructor of a struct type, the "this" keyword behaves exactly as an output parameter of the struct type
dub>>--
СТ>А в чем вопрос? :-)

dub>>A user-defined conversion is NOT allowed to which of the following types? 
dub>>Choice 1   
dub>> "struct" and "array" types  
dub>>Choice 2   
dub>> "abstract class" and "object" types  
dub>>Choice 3   
dub>> "object" and "interface" types  
dub>>Choice 4   
dub>> "struct" and "enum" types  
dub>>Choice 5   
dub>> "delegate" and "enum" types  
dub>>


СТ>Ответ 3. здесь


я уже разобрался почему но боюсь ссылка не по этому вопросу...
к object нельзя конвертить потому что в любом случае это будет каст к базовому типу который итак делается implicit

Error 1 'OneDemPoint.implicit operator object(OneDemPoint)': user-defined conversion to/from base class ...\OTHER\udc\Program.cs 26 23 udc


а вот с инетерфейсами пока не понял в чем причина ограничения и где про это можно прочитать:

Error 1 'OneDemPoint.implicit operator IFooInterface(OneDemPoint)': user-defined conversion to/from interface ...\OTHER\udc\Program.cs 26 23

Re[3]: Вопросы по с#
От: Сергей Туленцев Россия http://software.tulentsev.com
Дата: 22.09.06 12:23
Оценка: 1 (1)
Здравствуйте, dub, Вы писали:

dub>Здравствуйте, Сергей Туленцев, Вы писали:


dub>>>
dub>>>--
dub>>>Within an instance constructor of a struct type, the "this" keyword behaves exactly as an output parameter of the struct type
dub>>>--
СТ>>А в чем вопрос? :-)

dub>это утверждение верно? можно примерчик. что то я не пойму как this может быть output parameter?

Истинно. Можно делать, например, вот так:

[c#]
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {
        struct MyStruct
        {
            int Age;
            string Name;
            
            public MyStruct(int age)
            {
                this = new MyStruct(age, "Anonymous");    
            }
            
            public MyStruct(int age, string name)
            {
                Age = age;
                Name = name;
            }
            
            public override string ToString()
            {
                return string.Format("Age: {0}\t\tName: {1}", Age.ToString(), Name);
            }
            
        }
        
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            MyStruct ms = new MyStruct(42);
            Console.WriteLine(ms.ToString());
            Console.Read();
        }
    }
--
Re[3]: Вопросы по с#
От: Сергей Туленцев Россия http://software.tulentsev.com
Дата: 22.09.06 12:24
Оценка:
Здравствуйте, dub, Вы писали:

dub>Здравствуйте, Сергей Туленцев, Вы писали:


dub>>>
dub>>>--
dub>>>Within an instance constructor of a struct type, the "this" keyword behaves exactly as an output parameter of the struct type
dub>>>--


СТ>>А в чем вопрос?


dub>это утверждение верно? можно примерчик. что то я не пойму как this может быть output parameter?


Истинно. Можно делать, например, вот так:

    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {
        struct MyStruct
        {
            int Age;
            string Name;
            
            public MyStruct(int age)
            {
                this = new MyStruct(age, "Anonymous");    
            }
            
            public MyStruct(int age, string name)
            {
                Age = age;
                Name = name;
            }
            
            public override string ToString()
            {
                return string.Format("Age: {0}\t\tName: {1}", Age.ToString(), Name);
            }
            
        }
        
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            MyStruct ms = new MyStruct(42);
            Console.WriteLine(ms.ToString());
            Console.Read();
        }
    }
--
Re[3]: Вопросы по с#
От: Сергей Туленцев Россия http://software.tulentsev.com
Дата: 22.09.06 12:29
Оценка: 2 (1)
Здравствуйте, dub, Вы писали:


dub>а вот с инетерфейсами пока не понял в чем причина ограничения и где про это можно прочитать:

dub>

dub>Error 1 'OneDemPoint.implicit operator IFooInterface(OneDemPoint)': user-defined conversion to/from interface ...\OTHER\udc\Program.cs 26 23



Там, по ссылке, написано, что

User-Defined Conversions

Whatever we explained till now is the conversions (implicit or explicit) among the basic data types or among same user defined data types. Suppose we have to do conversions between basic data types and user defined data types or between two incompatible user-efined data types. C# provides a facility to define conversion operators inside a class or struct to achieve this.

But C# provides only certain user-defined conversions to be defined. In particular it is not possible to redefine an existing implicit or explicit conversion in C#. A class or struct is permitted to declare a conversion function from a source type S to a target type T only if all of the following are true.

1. Both S & T are different types.
2. Either S or T is a class or struct type in which the operator declaration takes place.
3. Neither S nor T is an object type or an interface type.
4. T is not a base class of S or S is not a base class of T.

The user-defined conversion can either implicit or explicit. The general form of user-defined conversion operator is as follows.

pblic static implicit/explicit operator type (arguments)

{

}

Where the operator is the required keyword and type is the required return type. Remember that operator function should be public and static and there is no return type. The presence of the keyword explicit makes the conversion as explicit and implicit keyword makes the conversion as implicit.

The conversion operator can be defined either inside the class or struct type. Remember that user defined conversions are not allowed to convert from or to interface types. Also note that since explicit or implicit keywords are not part of the method’s signature, it is not possible to declare both explicit and implicit conversion operator with a same source and target type.

An example for a user-defined conversion is shown below.

--
Re[2]: Вопросы по с#
От: dub  
Дата: 22.09.06 12:41
Оценка:
Здравствуйте, Сергей Туленцев, Вы писали:


dub>>
Which one of the following describes the OO concept of Aggregation?  
dub>>Choice 1   
dub>> A system of objects that define each other  
dub>>Choice 2   
dub>> A system of objects that are not related  
dub>>Choice 3   
dub>> A system of objects that implement each other  
dub>>Choice 4   
dub>> A system of objects inherited from each other  
dub>>Choice 5   
dub>> A system of objects that are built using each other  
dub>>


СТ>Ответ 5. Chapter 3 Object-Oriented Concept


1. а можно тогда узнать в чем принципиальная разница между
A system of objects that define each other && A system of objects that are built using each other


2. A system of objects that implement each other — что это вообще значит?
Re[3]: Вопросы по с#
От: cvetkov  
Дата: 22.09.06 13:08
Оценка:
да, отстал я от продвинутых технологий.
ни грамматики, ни копипаста не знаю
... << RSDN@Home 1.1.4 stable SR1 rev. 568>>
Re[3]: Вопросы по с#
От: Сергей Туленцев Россия http://software.tulentsev.com
Дата: 22.09.06 13:46
Оценка:
Здравствуйте, dub, Вы писали:

dub>Здравствуйте, Сергей Туленцев, Вы писали:


dub>1. а можно тогда узнать в чем принципиальная разница между

dub>A system of objects that define each other && A system of objects that are built using each other

Ну как бы ответ здесь содержится в самой формулировке. По определнию паттерна Aggregation мы видимо, что
должен быть объект, который содержит в себе (ссылки на) другие объекты и как-то их использует.

dub>2. A system of objects that implement each other — что это вообще значит?


Остальные же выражения, включая это, кажутся мне почти бессмысленными.
Хотя, в качестве иллюстрации к define each other можно было бы привести определение вложенных классво

class A
{
    class Nested!
    {}
    class Nested2
    {}

}


А к implement each other — реализацию интерфейсов и методов абкстрактных классов. Но ни то, ни другое не явлется
примером паттерна Aggregation.
--
Re[4]: Вопросы по с#
От: Сергей Туленцев Россия http://software.tulentsev.com
Дата: 22.09.06 13:47
Оценка: :)
Здравствуйте, Сергей Туленцев, Вы писали:

СТ>А к implement each other — реализацию интерфейсов и методов абкстрактных классов. Но ни то, ни другое не явлется

СТ>примером паттерна Aggregation.

Заранее прошу прощения за сумбурность и неполноту изложения. Просто пятница, вечер, и я уже немного пьян.
--
Re[3]: Вопросы по с#
От: Сергей Туленцев Россия http://software.tulentsev.com
Дата: 22.09.06 13:51
Оценка:
Здравствуйте, Lloyd, Вы писали:

L>Здравствуйте, cvetkov, Вы писали:



L>Копипаст все-таки иногда рулит.


Блин, жалко нет оценки "ну, более-менее согласен, но не совсем".
--
Re[4]: Вопросы по с#
От: Lloyd Россия  
Дата: 22.09.06 13:56
Оценка: :)
Здравствуйте, Сергей Туленцев, Вы писали:

L>>Копипаст все-таки иногда рулит.


СТ>Блин, жалко нет оценки "ну, более-менее согласен, но не совсем".


На этот случай есть смайлик.
... << RSDN@Home 1.1.4 stable SR1 rev. 568>>
Re[5]: Вопросы по с#
От: Аноним  
Дата: 22.09.06 14:59
Оценка:
Здравствуйте, Lloyd, Вы писали:

L>Здравствуйте, Сергей Туленцев, Вы писали:


L>>>Копипаст все-таки иногда рулит.


СТ>>Блин, жалко нет оценки "ну, более-менее согласен, но не совсем".


L>На этот случай есть смайлик.


все ясно
пятница
выходные впереди
да и форум используется не по назначению
Вопросы по с#
От: Аноним  
Дата: 23.09.06 11:57
Оценка:
>>dub Вопросы по с# из теста c BrainBench
>>

ггг. по поводу последнего вопроса — если в BrainBench такие вопросы, то микрософтовские экзамены просто рулят.
И лично мне совсем непонятно зачем нужно спрашивать определение и названия патанов в экзамене по конкретному языку. Как будто не зная названия патана уже и массив не объявить.
Более менее внятный вопрос это 1. Да и то, из-за формулировки вопроса. Могли бы, и пожалеть албанцев.

От хаоса в космос и далее к наличным


данное сообщение получено с www.gotdotnet.ru
ссылка на оригинальное сообщение
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.