Interview Question PART2

Default accessspecifier for a class
--------------------------------------------------------------------------------------------------------
1)Its internal by default and public can be made for non-nested types
2)Its private by default and any other can be used for nested type class

What are strong names in Assebliems
--------------------------------------------------------------------------------------------------------
A strong name consists of the assembly's identity — its simple text name, version number, and culture information (if provided) — plus a public key and a digital signature.

Nullable types in .NET
--------------------------------------------------------------------------------------------------------
In reality, most applications work with databases, which have their own type systems. The implications of working with database type systems is that you don’t have a one-to-one mapping between C# and database types. One glaring difference is that database types can be set to null. A database has no knowledge of reference and value types, which are C# language (.NET Platform) concepts. This means that C# value type equivalents in the database, such as int, decimal, and DateTime, can be set to null.

int? a= 5

means int a can be null also
checking if a is null

bool isNull=a==null;
Console.writeLine(isNull);

Yeild Keyword
--------------------------------------------------------------------------------------------------------
Yeild Keyword helps us to do stateful iteration or custom iteration over a collection
It will remember the state of iteration and assume the iteration form the state it left.Lets assume We have a list of integers which we will iterate
List = 1,2,3,4,5,6

During Iteration of the below Code. when the i has values <3 nothing happens, When the I has value more then 3 the yeild keyword send the value to the calling funtion . upon next iteration the loop starts from 5 which was the value that was left befor yeild makes a call to the calling function .So in this way yeild keyword preserves the value

a) Caller calls the function to iterate for number’s greater than 3.
b) Inside the function the for loop runs from 1 to 2 , from 2 to 3 until it encounters value greater than “3” i.e. “4”. As soon as the condition of value greater than 3 is met the “yield” keyword sends this data back to the caller.
c) Caller displays the value on the console and re-enters the function for more data. This time when it reenters, it does not start from first. It remembers the state and starts from “5”. The iteration continues further as usual.


class UnderstaingYield
    {
        List<int> mylist;

        public UnderstaingYield()
        {
            mylist = new List<int>();

            mylist.Add(1);
            mylist.Add(2);
            mylist.Add(3);
            mylist.Add(4);
            mylist.Add(5);
            mylist.Add(6);

        }



        public IEnumerable<int> iterateOver()
        {
            foreach (int i in mylist)
            {
                if (i > 3) yield return i;
            }
        }

    }

--MAIN--
           Console.WriteLine("Practice 4: understaning Yeild");
            UnderstaingYield UY = new UnderstaingYield();

            foreach (int i in UY.iterateOver())
            {
                Console.WriteLine(i);
            }

   


Comments

Popular posts from this blog

Authentication and Authorization in Web API -Part1

My Gardening Journey 6