⬆️ ⬇️

Questions about .NET №2

The first part of the questions can be found here.

We continue:



1) As it is known, System.Array does not implement IEnumerable <T>, ICollection <T>, IList <T>, where T is an array type (by the way, why?). However, using such arrays, you can use all that these interfaces provide (if the array contains only elements of the reference type). How is it going?



2) You have executed the following code:

Console.WriteLine(a.GetType()) ;

and got the result

SomeNamespace.SomeType[*];

What kind of person is that?



3) Which code will work faster and why?

A

...

Int32[] a = new Int32[100];

int len = a.Length;

for(Int32 index = 0; index < len; index++) {

//operations with a[index];

}

...




or

B

...

Int32[] a = new Int32[100];

for(Int32 index = 0; index < a.Length; index++) {

//operations with a[index];

}

...




4) what is the difference in the work between the following two methods:

private static Int32 M<T>(T t) where T: IComparable{...}

and

private static Int32 M(IComparable t) {...}



5) In the documentation, the Int32 type is defined as:

[SerializableAttribute]

[ComVisibleAttribute(true)]

public struct Int32 : IComparable, IFormattable,

IConvertible, IComparable<int>, IEquatable<int>



')

however, the following code will fail with a compilation error (int does not contain a def. for 'ToSingle'):



Int32 x = 5;

Single s = x.ToSingle();





Why is that?



6) Is there a way to get the return value of all methods when calling a chain of delegates, and not just the last one?



7) Which method can not apply any attribute?



That's all for today. Answers after discussion if need be :)



ps If you are minus, write for what at least ...

Source: https://habr.com/ru/post/62202/



All Articles