Results 1 to 7 of 7

Thread: C# Interview Questions

  1. #1

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861

    C# Interview Questions

    I initially posted this in Chit Chat, so some of you may have seen it, some of you may not....anyway these are some questions I was asked at an interview I had the other day. What I would like is to compare my answers with your guys to determine if I answered them correctly or at least closely...my answers are below the questions.

    Code:
    C# Questions
    
    1. What does the keyword static mean when applied to a class member?
    
    2. Declare a method called calculate that takes one integer, adds one and returns the result.  Allow this method to be overridden by an inheriting class.
    
    3. What is the difference between a class and a struct?
    
    4. What is the difference between a class and an interface?
    
    5. What are the .Net web authentication options and which one would generally be used for a secured/public site?
    
    6. What are some .Net options for maintaining session state?
    
    7. What is a Singleton?
    
    
    Database Questions
    
    Using the EMPLOYEE and JOBS tables, fill in the following stored procedure template so that it removes a job by job_id and all associated employees ensuring that both updates succeed or fail together.
    
    CREATE PROCEDURE deleteJob @jobid smallint AS
    My Answers
    Code:
    1. It means the method can be called through the class without instantiating the class.
    
    2. 
    Public virtual int calculate(int value)
    {
    	newValue = value + 1;
    	return newValue;
    }
    
    3. The class object is stored in the heap and struct object is stored in the stack. Therefore accessing and removing data from the struct is faster than for a class.
    
    4. You can instantiate a class but you cannot instantiate an interace you can only offer the functionality of that interface.
    
    5. None
       Windows Authentication –Secured side
       IIS Authentication
       Forms Authentication – Public Side
    
    6. In process and out of process. (wasn't sure about this one?)
    
    7. This ensures that a class can only be instantiated once.
    
    
    Database Answer:
    
    CREATE PROCEDURE deleteJob @jobid smallint AS 
    
    BEGIN
    BEGIN TRAN
    IF EXISTS (SELECT * FROM JOBS WHERE job_id = @jobid)
    	DELETE FROM JOBS WHERE job_id = @jobid
    IF @@ERROR <> 0
    	BEGIN
    	RAISERROR(‘Could not delete row from Jobs – Abort’, 16,1)
    	GOTO Errorhandler
    	END
    IF EXISTS(SELECT * FROM EMPLOYEES WHERE job_id = @jobid)
    DELETE FROM EMPLOYEES 
    		WHERE job_id = @jobid
    IF @@ ERROR <> 0
    	BEGIN
    	RAISERROR(‘Could not delete row from Employees – Abort’, 16,1)
    	GOTO Errorhandler
    	END
    COMMIT
    RETURN
    Errorhandler:
    	ROLLBACK TRAN
    	RETURN
    END
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You gave some good answers. The db question had be stumped since I know nothing about writing stored procs. Number 6 would be the session object or the cache.

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I already gave you my answers in the Chit Chat..., here is some more information:
    1. Yes, you can call the method without instantiating an object from it, but it also allows all objects to share the same method that doesn't depend on which instance it was called on.

    2. You had:
    Code:
    Public virtual int calculate(int value)
    {
    	newValue = value + 1;
    	return newValue;
    }
    First, newValue is never declared, so it wouldn't compile. Also, there is no need to have another variable to do this:
    Code:
    Public virtual int calculate(int value)
    {
    	return value++;
    }

    6. Yes, there is the session object and the cache as devgrp said, but there is also the querystring and cookies.


    I liked your stored proc.

    Did you get the job?

  4. #4

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    don't know yet, I haven't heard back from them...seeing as how i wrote the calculate method wrong....I'm not sure if I will hear from them.

    I guess you could write the calculate method a couple of different ways...
    Code:
    Public virtual int calculate(int value)
    {
       int newValue = value + 1;
       return newValue;
    
       OR
    
       value++;
       return value;
    
       OR
    
       value += 1;
       return value;
    }
    they all do the same thing. I wrote the method very quickly (didn't test it), and I can't believe 1) I wrote it in that form and 2) that I didn't declare the newValue variable.

    Oh well, I had another interview yesterday, and that one went pretty good...They even said I was their best candidate so far...both in person and on paper....so maybe that one will work out.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Did you write it using VS.NET or just on paper?

  6. #6

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    just wrote it on paper.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    The interview doesn't evalute your actual ability in programming . There are lots of hard work we do , they don't ask about (or maybe they don't dare to argue with ). They should give you a computer and instruct you to build a demo or some functions rather than writing them on a paper . I hate theoritical discussion . I like to writing silently .
    Good Luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width