.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> C# >> Post New Question Subscribe to Interview Questions

How to assign a value to a readonly variable in C#

Posted By :Narayanan     Posted Date :September 03, 2011    Points :40   Category :C# 
using constructor

You can also find related Interview Question to How to assign a value to a readonly variable in C#  below: 

Is it possible to set SessionState to readonly mode? Readonly mode means, we can only read data from session but we can not write any data in session variable?

  
Yes, it is possible.
EnableSessionState property has a value "Readonly" which actually makes the session state read only.

Thanks. (More...)

can we assign Null value to Struct variable.

  
No , We cannot assign null to a struct variable, since structs are value type. (More...)

HOW TO ASSIGN VALUE TO PARAMETERS USED IN QUERY WHICH IS STORED IN A VARIABLE?

  
Have a look at the following sql block

DECLARE
/* @STRQUERY AND @PARAMDEF SHOULD BE NVARCHAR
BECAUSE "EXECUTE sp_executesql" ACCEPTS STATEMENT AND PARAMETER OF TYPE 'ntext/nchar/nvarchar' ONLY
OTHERWISE
"Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'."
OR
"Procedure expects parameter '@parameters' of type 'ntext/nchar/nvarchar'." WILL BE RAISED*/
@STRQUERY AS NVARCHAR(200),
@STRNAME AS VARCHAR(100),
@PARAMDEF AS NVARCHAR(100),
@STRNAMEVALUE AS VARCHAR(100)
BEGIN
--FOLLOWING STATEMENT ASSING VALUE
SET @STRNAMEVALUE='MANINDER'
--FOLLOWING VARIABLE CONTAINS A QUERY WHICH USES A PARAMETER
SET @STRQUERY = 'SELECT ''YOUR NAME IS '' + @STRNAME'

--FOLLOWING STATEMENT DEFINES THE PARAMETERS USED IN THE QUERY
SET @PARAMDEF = '@STRNAME AS VARCHAR(100)'

--IN THE FOLLOWING STATEMENT "@STRNAME = @STRNAMEVALUE" STATEMENT ASSIGNS VALUE TO THE PARAMETER
--SYNTAX IS EXECUTE sp_executesql @STATEMENT, @PARAMETERS
EXECUTE sp_executesql @STRQUERY, @PARAMDEF,@STRNAME = @STRNAMEVALUE;
END (More...)

How to remove a Session variable?

  
using HttpSessionState.Remove(); (More...)

I was trying to use an "out int" parameter in one of my functions. How should I declare the variable that I am passing to it?

  
You should declare the variable as an int, but when you pass it in you must specify it as 'out', like the following: int i; foo(out i); where foo is declared as follows: [return-type] foo(out int o) { } (More...)

can we use session variable in App_code Class page ?

  
Yes.
By using "HttpContext.Current.Session("VarName") ", we can use current session variable in App_code Class page (More...)

Can you change the value of a variable while debugging a C# application?

  
Yes, if you are debugging via Visual Studio.NET, just go to Immediate window. (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend