473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Question regarding C#

Hi

Please Could you tell me what make these 2 pieces of code behave differently in visual studio .NET

#
tcPacket.Data = new byte[1]
tcPacket.Data[0] = GET_CURRENT_MODE

#
tcPacket.Data = new byte[1]{GET_CURRENT_MODE}

During execution of the code, in case#1 tcPacket.Data allways point to NULL while in case #2 tcPacket.Data don't

Thanks
Franck
Nov 15 '05 #1
3 1480
In case 1, the byte[] consists of intialized data when you assign it to the
property. My guess is that set_Data (if .Data is a property) is checking
for just an "empty" array, and setting it to null.

However, if Data was a local or a field, they'd not be null at either
points.

What type is tcPacket? Can you make a short but complete program to
reproduce this?

-mike
MVP

"Franck Sodogandji" <fs*********@hotmail.com> wrote in message
news:24**********************************@microsof t.com...
Hi,

Please Could you tell me what make these 2 pieces of code behave differently in visual studio .NET ?
#1
tcPacket.Data = new byte[1];
tcPacket.Data[0] = GET_CURRENT_MODE;

#2
tcPacket.Data = new byte[1]{GET_CURRENT_MODE};

During execution of the code, in case#1 tcPacket.Data allways point to NULL while in case #2 tcPacket.Data don't.
Thanks
Franck

Nov 15 '05 #2
Well, this is just my 5c but isnt it a case of #1 is getting intialized to
null (ex MyClass mc = new MyClass() <-- new instance returns null) so in
this case #1 returns null and #2 get intialised and assigned so it isnt
null...

I hope this is right.

Mitch

"Michael Giagnocavo [MVP]" <mg*******@Atrevido.net> wrote in message
news:#7**************@tk2msftngp13.phx.gbl...
In case 1, the byte[] consists of intialized data when you assign it to the property. My guess is that set_Data (if .Data is a property) is checking
for just an "empty" array, and setting it to null.

However, if Data was a local or a field, they'd not be null at either
points.

What type is tcPacket? Can you make a short but complete program to
reproduce this?

-mike
MVP

"Franck Sodogandji" <fs*********@hotmail.com> wrote in message
news:24**********************************@microsof t.com...
Hi,

Please Could you tell me what make these 2 pieces of code behave

differently in visual studio .NET ?

#1
tcPacket.Data = new byte[1];
tcPacket.Data[0] = GET_CURRENT_MODE;

#2
tcPacket.Data = new byte[1]{GET_CURRENT_MODE};

During execution of the code, in case#1 tcPacket.Data allways point to

NULL while in case #2 tcPacket.Data don't.

Thanks
Franck


Nov 15 '05 #3
Case #1 creates a new array, and assigns it to the property (I'm guessing
it's a property?). I'm not aware of any case where the newarr will return
null. It'd have to throw an exception if there was a problem.

I compiled this (using a local): The only difference when they are compiled
is that the 2nd one has a non-zero (I'm guessing non-zero) value for its
only element, while case 2 assigns an array with a zero value for its
element, then assigns another value to the element.

-mike
MVP

"Mitchell Geere" <mg****@telkomsa.net> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
Well, this is just my 5c but isnt it a case of #1 is getting intialized to
null (ex MyClass mc = new MyClass() <-- new instance returns null) so in
this case #1 returns null and #2 get intialised and assigned so it isnt
null...

I hope this is right.

Mitch

"Michael Giagnocavo [MVP]" <mg*******@Atrevido.net> wrote in message
news:#7**************@tk2msftngp13.phx.gbl...
In case 1, the byte[] consists of intialized data when you assign it to

the
property. My guess is that set_Data (if .Data is a property) is checking for just an "empty" array, and setting it to null.

However, if Data was a local or a field, they'd not be null at either
points.

What type is tcPacket? Can you make a short but complete program to
reproduce this?

-mike
MVP

"Franck Sodogandji" <fs*********@hotmail.com> wrote in message
news:24**********************************@microsof t.com...
Hi,

Please Could you tell me what make these 2 pieces of code behave

differently in visual studio .NET ?

#1
tcPacket.Data = new byte[1];
tcPacket.Data[0] = GET_CURRENT_MODE;

#2
tcPacket.Data = new byte[1]{GET_CURRENT_MODE};

During execution of the code, in case#1 tcPacket.Data allways point to

NULL while in case #2 tcPacket.Data don't.

Thanks
Franck



Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Francis Lavoie | last post by:
Hello I have some questions regarding webframework, I must say that I quite lost and these questions are basicly to help me understand the way it work. I have some knowledge with PHP and JSP....
2
by: Jo_Calico | last post by:
I love the Dynamic Drive cross browser marquee script. I'd like to make the text loop immediately after completion, so the beginning runs right after the end (does that make sense?). Could anyone...
3
by: Samuel | last post by:
I wrote a very simple httpmodule and tried to compile it with no success. This is my code: ============== Imports System Imports System.Web Imports Microsoft.VisualBasic NameSpace...
7
by: Squignibbler | last post by:
Hi all, I have a question regarding the C++ programming language regarding the nature of the relationship between pointers and arrays. If the statement MyArray is functionally identical to...
6
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
14
by: Mr Newbie | last post by:
I am often in the situation where I want to act on the result of a function, but a simple boolean is not enough. For example, I may have a function called isAuthorised ( User, Action ) as ?????...
2
by: Dean R. Henderson | last post by:
For an ASP.NET web application, is there a way for one session (with appropriate security authorization) to set a HttpSessionState variable to point to another session and execute the Abandon...
6
by: Jon | last post by:
All, I'm working in a fairly robust content management system for our company's websites, and have a question regarding the file and directory structure of the site. Currently, I'm populating...
5
by: archana | last post by:
Hi all, I am using timer to do some functionality on user specified time. I am using system.timers.timer class and its timer to do this functionality. What i am doing is i set autoreset to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.