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>
Здравствуйте, 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>
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>
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>
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>--
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.
Здравствуйте, 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();
}
}
Здравствуйте, Сергей Туленцев, Вы писали:
СТ>А к implement each other — реализацию интерфейсов и методов абкстрактных классов. Но ни то, ни другое не явлется СТ>примером паттерна Aggregation.
Заранее прошу прощения за сумбурность и неполноту изложения. Просто пятница, вечер, и я уже немного пьян.
Вопросы по с# из теста 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
--
Здравствуйте, Сергей Туленцев, Вы писали:
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?
Здравствуйте, 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-параметр.
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>>
я уже разобрался почему но боюсь ссылка не по этому вопросу...
к object нельзя конвертить потому что в любом случае это будет каст к базовому типу который итак делается implicit
Error 1 'OneDemPoint.implicit operator object(OneDemPoint)': user-defined conversion to/from base class ...\OTHER\udc\Program.cs 26 23 udc
а вот с инетерфейсами пока не понял в чем причина ограничения и где про это можно прочитать:
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>>
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 — что это вообще значит?
Здравствуйте, 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.
Здравствуйте, Lloyd, Вы писали:
L>Здравствуйте, cvetkov, Вы писали:
L>Копипаст все-таки иногда рулит.
Блин, жалко нет оценки "ну, более-менее согласен, но не совсем".
--
Re[5]: Вопросы по с#
От:
Аноним
Дата:
22.09.06 14:59
Оценка:
Здравствуйте, Lloyd, Вы писали:
L>Здравствуйте, Сергей Туленцев, Вы писали:
L>>>Копипаст все-таки иногда рулит.
СТ>>Блин, жалко нет оценки "ну, более-менее согласен, но не совсем".
L>На этот случай есть смайлик.
все ясно
пятница
выходные впереди
да и форум используется не по назначению
Вопросы по с#
От:
Аноним
Дата:
23.09.06 11:57
Оценка:
>>dub Вопросы по с# из теста c BrainBench >>
ггг. по поводу последнего вопроса — если в BrainBench такие вопросы, то микрософтовские экзамены просто рулят.
И лично мне совсем непонятно зачем нужно спрашивать определение и названия патанов в экзамене по конкретному языку. Как будто не зная названия патана уже и массив не объявить.
Более менее внятный вопрос это 1. Да и то, из-за формулировки вопроса. Могли бы, и пожалеть албанцев.