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
DANIEL PEREIRA
NA
4
623
Method must have a return type
Dec 25 2017 9:55 AM
Folks, I am an engineer who learned Pascal back in my day and I am trying to get around object-oriented languages, with limited success. I'm just getting started on C#, so please bear with me.
I copied some code I found at https://blogs.msdn.microsoft.com/dawate/2009/06/24/intro-to-audio-programming-part-3-synthesizing-simple-wave-audio-using-c/ and now I am trying to run it, but there's something wrong at line 128.
The original code was
public
enum
WaveExampleType
{
ExampleSineWave = 0
}
public
class
WaveGenerator
{
// Header, Format, Data chunks
WaveHeader header;
WaveFormatChunk format;
WaveDataChunk data;
///
}
public
WaveGenerator(WaveExampleType type)
{
// Init chunks
header =
new
WaveHeader();
format =
new
WaveFormatChunk();
data =
new
WaveDataChunk();
// Fill the data array with sample data
switch
(type)
{
case
WaveExampleType.ExampleSineWave:
// Number of samples = sample rate * channels * bytes per sample
uint
numSamples = format.dwSamplesPerSec * format.wChannels;
// Initialize the 16-bit array
data.shortArray =
new
short
[numSamples];
int
amplitude = 32760;
// Max amplitude for 16-bit audio
double
freq = 440.0f;
// Concert A: 440Hz
// The "angle" used in the function, adjusted for the number of channels and sample rate.
// This value is like the period of the wave.
double
t = (Math.PI * 2 * freq) / (format.dwSamplesPerSec * format.wChannels);
for
(
uint
i = 0; i < numSamples - 1; i++)
// Fill with a simple sine wave at max amplitude
for
(
int
channel = 0; channel < format.wChannels; channel++)
{
data.shortArray[i + channel] = Convert.ToInt16(amplitude * Math.Sin(t * i));
}
}
// Calculate data chunk size in bytes
data.dwChunkSize = (
uint
)(data.shortArray.Length * (format.wBitsPerSample / 8));
break
;
}
}
But I get the return type error for line 1. (line 128 at this online editor: http://rextester.com/KOVPK29971). What is wrong here? I get that the intention was to leave room for a future implementation of a different WaveExampleType using the switch/case thing, but why does one have to write anything inside the parenthesis in line 1 and why does it have the same name as the class?
I know it's a very simple thing, and I realize the point is I don't understand the whole point behind creating a class and then something else with the same name. Remember, I learned Pascal. Could someone please point how to correct the code and the idea behind it? Thanks in advance!
Reply
Answers (
2
)
upload excel and store into database using mvc 5
Displaying Images in a GridView Column