|
-
Jul 23rd, 2003, 03:24 PM
#1
Thread Starter
Frenzied Member
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
-
Jul 23rd, 2003, 03:48 PM
#2
Frenzied Member
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.
-
Jul 23rd, 2003, 04:13 PM
#3
PowerPoster
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?
-
Jul 23rd, 2003, 04:57 PM
#4
Thread Starter
Frenzied Member
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
-
Jul 23rd, 2003, 07:14 PM
#5
Frenzied Member
Did you write it using VS.NET or just on paper?
-
Jul 23rd, 2003, 09:59 PM
#6
Thread Starter
Frenzied Member
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jul 24th, 2003, 08:46 AM
#7
Sleep mode
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|