473,503 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to write structure

1 New Member
Expand|Select|Wrap|Line Numbers
  1. struct info
  2.         {
  3.             string name, ID;
  4.             double GPA;
  5.         };
  6.  
  7.         static void Main(string[] args)
  8.         {
  9.             info[] student=new info [5];
  10.             Console.WriteLine("Enter the data : ");
  11.             for (int i = 0; i < 5; i++)
  12.             {
  13.                 student[i] = Console.ReadLine();
  14.             }
when i write this code it give me error
("Cannot implicitly convert type 'string' to 'ass.Program.info[]' ")

can i know what's the error about this code
Aug 12 '12 #1
2 2012
Rabbit
12,516 Recognized Expert Moderator MVP
You're trying to assign a string (the string you read from the console) into your struct (info). They are not the same type. A string is not the same thing as a struct.
Aug 12 '12 #2
Frinavale
9,735 Recognized Expert Moderator Expert
Rabbit is referring to line 13 in the above code.
You have:
Expand|Select|Wrap|Line Numbers
  1.  student[i] = Console.ReadLine();
But it should be something like:
Expand|Select|Wrap|Line Numbers
  1. student[i].Name = Console.ReadLine();
If you are reading in a name at that point.

If you're reading in the GPA then it should be:
Expand|Select|Wrap|Line Numbers
  1. student[i].GPA = Console.ReadLine();
If you are expecting a string with all of the information about the student, then you should either create a function that accepts a string and puts the relevant information into the appropriate members of the struct...or you should consider implementing a constructor that takes a string and does this same process.

-Frinny
Aug 13 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
612
by: Stephan Tobies | last post by:
Hi everyone, I am looking for a good data structure that could be used to represent families of trees with shared sub-trees and copy-on-write semantics. On a very abstract level, I would like...
7
3412
by: Randy Yates | last post by:
Hi, I work in an embedded environment in which we often use a mix of C and assembly code. Thus a recurring requirement is to be able to take a C header file with structure definitions as input...
3
14488
by: Dae-Suk Chung | last post by:
Hi, What is the easiest way to write a struct(with biary data) to a file ? do I need to covert it through e.g. Marshal class ? Thanks for any tips! DaeSuk.
5
4318
by: Phil Kelly | last post by:
Hi I need to write the contents of a structure to a binary file - there is one string and 2 integers, but I can't seem to figure out how to write the data correctly. If I am simply writing...
8
23884
by: a | last post by:
I have a struct to write to a file struct _structA{ long x; int y; float z; } struct _structA A; //file open write(fd,A,sizeof(_structA)); //file close
2
1133
by: Hexman | last post by:
Hi All, I have created a structure for a record (as I did in the old days with assembler, cobol, etc.). It contains several fields with various types. Using it in arrays it functions nicely. ...
2
11433
by: shivapadma | last post by:
1.i am just trying to insert a "structure record" into a file using fwrite() function by the following code 2. #include<stdio.h> #include<conio.h> struct student { char name; int rollno;...
5
3793
by: zehra.mb | last post by:
Hi, I had written application for storing employee data in binary file and reading those data from binary file and display it in C language. But I face some issue with writing data to binary file....
5
3773
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
11
3917
by: michelqa | last post by:
Hello, I can retrieve column text from a ListView in another process but I cant figure out how to access to structure elements (LVCOLUMN) <code> //Handle variable is a valid ListView handle ...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.