TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maha
NA
0
328.6k
As casting
Oct 23 2013 11:08 AM
What is the different between
as
casting and usual casting. Because this program is executing with usual casting, when it is done on
string
data type but with
StringBuilder
data type program is not executing with usual casting. Please explain the reason. This program is given in the following website. Problem is highlighted.
http://www.dotnetperls.com/as
using System;
using System.Text;
class Program
{
static void Main()
{
// Create a string variable and cast it to an object.
string variable1 = "carrot";
object variable2 = variable1;
// Try to cast it to a string.
//string variable3 = variable2 as string;
string variable3 = (string)variable2;
if (variable3 != null)
{
Console.WriteLine("have string variable");//have string variable
}
// Try to cast it to a StringBuilder.
//StringBuilder variable4 = variable2 as StringBuilder;
StringBuilder variable4 = (StringBuilder)variable2;
if (variable4 != null)
{
Console.WriteLine("have StringBuilder variable");
}
Console.Read();
}
}
//have string variable
Reply
Answers (
5
)
where I will get all the latest technologies news about s/w?
How to set a Paging in Picturebox images in C# windows forms