Skip to content
Home » [Update] 10 คำสั่ง C# ย่อ Code ให้สั้นลง | can not ย่อ – NATAVIGUIDES

[Update] 10 คำสั่ง C# ย่อ Code ให้สั้นลง | can not ย่อ – NATAVIGUIDES

can not ย่อ: นี่คือโพสต์ที่เกี่ยวข้องกับหัวข้อนี้

Posted by Basketman under C#

1. The ? conditional evaluation operator
เป็นการย่อคำสั่งที่เป็นเงื่อนไข  if .. then .. else จากเดิม

int x = 10;
int y = 20;
int max;
if (x > y)
max = x;
else
max = y;

เขียนใหม่เป็น

int x = 10;
int y = 20;
int max = (x > y) ? x : y;

2. Null-Coalesce operator (??)
เป็นการตรวจสอบค่า  null  ของตัวแปล เช่น

object cache = null;
object d = new object();
object e;
if (c != null)
e = c;
else
e = d;

หรือ

object cache = null;
object d = new object();
object e = (c != null) ? c : d;

เราสามารถใช้เครื่องหมาย “??” เพื่อทำให้สั้นลงเขียนใหม่เป็น

object cache = null;
object d = new object();
object e = c ?? d;

3. Object Initializers
 เวลาที่เราประกาศ  instance  ของ  class  เรามักจะเขียนแบบนี้

Customer c = new Customer();
c.Name = "James";
c.Address = "204 Lime Street";

สามารถเขียนให้สั้นลงเป็น

Customer c = new Customer { Name="James", Address = "204 Lime Street" };

 
4. The using statement
เวลาที่เรียกใช้และกำหนดค่า  System Resouce  เช่น Font , File , Network  ต่างๆ เราจะเขียนแบบนี้

     // 1. Allocation of the object
     Font font1 = new Font("Arial", 10.0f);
try
{
// 2. The bit where we use the resource
     }
finally
{
// 3. Disposal of the object
     if (font1 != null)
((IDisposable)font1).Dispose();
}

 เราสามารถเขียนได้อีกแบบคือ

 // Allocate the resource
 using (Font font1 = new Font("Arial", 10.0f))
{
// The bit where we use the resource
 }
 // Disposal is automatic

 

5. Aliases for long winded namespaces and types

เรียกใช้  NameSpace แบบเร่งรัด 

using Word = Microsoft.Office.Interop.Word;
...
Word.Application = new Word.Application() { Visible = True; }

6. Nullable objects
เราสามารถกำหนด Data type  ให้สามารถมีค่า null ได้

Nullable<int> x = null;
int? x = null;

7. Automatic Properties
ใน C# 3.0 เราสามารถกำหนด properties ได้อย่างรวดเร็ว   ปกติเราจะเขียนแบบนี้

public class Person
{
private string _firstName;
public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
}

เขียนใหม่เป็น

public class Person
{
public string Firstname { get; set; }
}

 

8. Type inference
 การประกาศตัวแปลจากเดิม

string MyString = “Hello World”;

 เขียนใหม่ได้เป็น

var MyString = “Hello World”;

 
9. Lambda Expressions
 ใน C# 2.0 จะมี anonymous methods  และมี  delegate มาเกี่ยวข้อง เช่น
 

 Func mySeniorStaffFilter = delegate(int a) { return a > 35; };

 เราสามารถใช้ syntax ของภาษา Lamda  สามารถเขียนให้อ่านง่ายขึ้น

Func mySeniorStaffFilter = a => a > 35;

และสามารถเขียนได้ทุกที่ ที่เราต้องการ filtter ข้อมูล

var SeniorStaff = Employees.Where(s => s.Age > 35);

 
10. string.IsNullOrEmpty
ใช้   string.IsNullOrEmptyเพื่อตรวจสอบ  ข้อมูลว่าง และ ข้อมูลมีค่าเป็น  null  เฉพาะข้อมูลที่เป็น string

if (String.IsNullOrEmpty(s) == true)
return "is null or empty";
else
return String.Format("(\"{0}\") is not null or empty", s);
ที่มา: http://codesnippet.exteen.com/20090827/10-c-code

Share this:

Like this:

Like

Loading…

[Update] หลักการใช้ Can กับ Could ใช้ยังไง มาดูกันเลยจ้า… | can not ย่อ – NATAVIGUIDES

33

SHARES

Facebook

Twitter

หลักการใช้ Can กับ Could นอกจากเพื่อบอกความสามารถแล้ว ยังสามารถใช้ในกรณีอื่นๆได้ด้วยครับ มีอะไรบ้างนั้นไปดูกันเลย

  • can แคน >> can’t แค้น/ cannot แคนน็อท
  • could คุด  >> couldn’t คุดดึนท / could not คุด น็อท

คำว่า can กับ could แปลว่า สามารถทำได้

แต่ can เป็นปัจจุบัน ส่วน could เป็นอดีต

หลักการใช้ Can กับ Could

can could

ตัวอย่างการใช้ can

  • I can swim fast. ฉันสามารถว่ายน้ำได้เร็ว
  • You can’t play golf. คุณไม่สามารถเล่นกอล์ฟได้
  • He can sing very well. เขาสามารถร้องเพลงได้ดี
  • She cannot use a computer. หล่อนไม่สามารถใช้คอมพิวเตอร์ได้
  • A kangaroo can jump very far. จิงโจ้สามารถกระโดดได้ไกล
  • They can’t play the guitar? พวกเขาไม่สามารถเล่นกีต้าร์ได้

Can you swim? คุณว่ายน้ำเป็นไหม
Yes, I can. ใช่ ฉันสามารถ (ว่ายน้ำเป็น)

Can he sing? เขาร้องเพลงเป็นไหม
Yes he can. ใช่ เขาสามารถ (ร้องเพลงเป็น)

Can’t she use a computer? หล่อนไม่สามาถใช้คอมพิวเตอร์ได้ ใช่ไหม
No, she cant’. ไม่ หล่อนไม่สามารถ (ใช้คอมพิวเตอร์)

Can’t they play the guitar? พวกเขาไม่สามารถเล่นกีต้าร์ได้ใช่ไหม
No, they can’t. ไม่ พวกเขาไม่สามารถ(เล่นกีต้าร์)

ตัวอย่างการใช้ Could

I could speak Chinese when I was seven.
ฉันสามารถพูดจีนได้ ตอนฉันอายุ 7 ขวบ

She could skate by the age of 10.
หล่อนสามารถเล่นสเกตได้ ตอนอายุ 10 ปี

He could ride a bike when he was young.
เขาสามารถขี่จักรยานได้ ตอนเขาเป็นเด็ก

Could you swim when you were six?
No, I couldn’t. I could swim when I was ten.
คุณว่ายน้ำเป็นไหม ตอนคุณอายุ 6 ขวบ
ไม่ ไม่ได้ ฉันสามารถว่ายน้ำได้ตอนฉันอายุ 10 ปี

  • หลักการใช้ Can กับ Could เพื่อขอร้องหรือยื่นข้อเสนอ

การใช้ can กับ could ในการขอร้องจะเป็นรูปประโยคคำถามครับ แต่ไม่ใช่คำถาม

Can you open the door, Jo?

ประโยคด้านบนเป็นการขอร้องว่า ” ช่วยเปิดประตูให้หน่อย โจ” ไม่ใช่การถามว่า ” เปิดประตูได้หรือเปล่า โจ”

แต่จากตัวอย่างด้านบนก็อาจจะเป็นการถามความสามารถก็ได้ ถ้าเหตุการณ์นี้เกิดขึ้นในภาพยนต์ ซึ่งในฉากนั้นมีประตูบานใหญ่ หนักมาก ทุกคนสามารถเปิดประตูได้ เพราะล้วนแต่แข็งแรง แต่มีคนหนึ่งดูแล้วไม่น่าจะมีเรี่ยวแรงเลย แล้วเพื่อนๆ ถามว่า ” Can you open the door, Jo?”  ถ้าเป็นอย่างนี้ คงหมายถึง ” คุณเปิดประตูได้หรือเปล่าโจ” อย่างแน่นอน

การใช้ Could ในประโยคขอร้อง จะสุภาพกว่า Can ครับ

ต่อไปนี้ไม่ใช่ประโยคคำถาม ดังนั้นห้ามตอบว่า yes หรือ no

Can I have your name, please?
Could I have your name, please?
ดิฉันขอทราบชื่อของคุณด้วยค่ะ (คุณชื่ออะไรคะ)

Can you tell me the way to the bank, please?
Could you tell me the way to the bank, please?
คุณช่วยบอกทางไปธนาคารด้วยครับ (ธนาคารไปทางไหนครับ)

Can I use your computer?
Could I use your computer?
ฉันขอใช้คอมพิวเตอร์ของคุณได้ไหม

Can you help me?
คุณช่วยผมหน่อยได้ไหมครับ

ตัวอย่างด้านบนเป็นการร้องขอ ไม่ใช่การถาม ดังนั้น ถ้าจะตอบสำนวนเหล่านี้ สามารถใช้คำเหล่านี้โต้ตอบได้เลย

Sure.
Certainly.
Of course.

สามคำนี้ ต่างแปลว่า ได้สิ

ส่วนตัวอย่างด้านล่างนี้เป็นการยื่นข้อเสนอครับ

Can I help you?
ให้ผมช่วยคุณไหม
Thank you. Open the door, please.
ขอบคุณคะ

ขอ 5 ดาวให้บทเรียนด้วยครับผม…

คลิกดาวดวงที่ขวามือสุดเลยครับครับ…

Average rating 4.6 / 5. Vote count: 313

ยังไม่มีใครให้ดาว คุณคือคนแรก….


Hakan Akkus – I Can’t Be (Drop G \u0026 Regard Remix)


Follow our Spotify Playlist: https://spoti.fi/2IuhPDy
Send Your Original Mixes \u0026 Official Remixes: Gmail:[email protected]
p.s. Support artists and video makers by clicking on the link below…Thank You!!!

For More Music Join Us ON FaceBook:
https://www.facebook.com/NewEntrySong
https://www.facebook.com/VdjRossoneroOfficial
https://www.facebook.com/groups/VdjRossonero
For More:
Drop G Facebook: https://www.facebook.com/dropgdj
Regard Facebook: https://www.facebook.com/Djregard
Label: TFB Records

Video Credit:
006:02
Produced by: Chris Norton
Web: http://www.skyvisionvi.com
Facebook: https://www.facebook.com/SkyVisionVI

นอกจากการดูบทความนี้แล้ว คุณยังสามารถดูข้อมูลที่เป็นประโยชน์อื่นๆ อีกมากมายที่เราให้ไว้ที่นี่: ดูเพิ่มเติม

Hakan Akkus - I Can't Be (Drop G \u0026 Regard Remix)

I Can | Simple Song for Children Learning English


I have written this song for my ESL lessons to teach basic actions to children. The song is very simple so I use it to teach English to preschoolers and elementary school kids. Your children not only can learn the English modal verb “can” with this song but also some everyday actions such as “run”, “walk”, “sleep” etc. This song can be used to introduce English animals such as giraffe, bird, snake, whale etc.
It will be more fun if a teacher can invent activities in the classroom to repeat the actions in the song lyrics. Children can run, walk and crawl while singing the song. In such a way they are more likely to remember the song vocabulary and get effectively trained to use the verb “can”. So I hope educators and parents as well as their kids will have fun using my song for teaching English as a second language.
You can find the \”I Can\” song lyrics along with flash cards and worksheets based on this video on my ESL blog at http://english4kidsstepbystep.blogspot.com/2014/09/icanactionverbssongforkids.html
Lyrics:
Yes, I can, I can.
Yes, I can.
Yes, I can, I can.
Yes, I can.
I can jump, jump, jump like a kangaroo.
I can swim, swim, swim like a whale, too.
I can walk, walk, walk like a tall giraffe,
And like an ostrich I can run.
Yes, I can, I can.
Yes, I can.
Yes, I can, I can.
Yes, I can.
I can crawl, crawl, crawl like a jungle snake,
I can sleep, sleep, sleep like a sloth all day,
I can fly, fly, fly like a bird in the sky,
And like a monkey I can climb.
Yes, I can, I can.
Yes, I can.
Yes, I can, I can.
Yes, I can.

You can BUY the instrumental version (music without vocal) of the I Can song in mp3 format and in better quality than here on Youtube at https://englishforkidz.onfastspring.com/icansonginstrumentalmp3

I Can | Simple Song for Children Learning English

[Vietsub] Can’t Get You Out Of My Head – glimmer of Blooms


[Vietsub] Can't Get You Out Of My Head - glimmer of Blooms

Cannot, Can Not, Can’t – Learn English Grammar


In this video, learn the difference between: ‘cannot’, ‘can not’ and ‘can’t’.
Cannot is the negative form of the verb can. Simply replace ‘can’ with ‘cannot’ to make the sentence negative. Notice how ‘cannot’ is one word, with two n’s.
Can’t is the contracted form of ‘cannot’. You can think of it as the short form. To use it, simply replace ‘can’ with ‘can’t’ to make the sentence negative. ‘Can’t’ is the most common choice in American English and using it will help you sound fluent and natural.
‘Can not’ is not the negative form of the verb can. If you use it as the negative form, it’s a spelling mistake. It is grammatically possible to have ‘can’ and ‘not’ side by side in a sentence. This can happen if the verb of your sentence is ‘can’ and then you have an expression with not, like ‘not only X, but also Y’. This isn’t common, but it is possible.
Watch the lesson now to learn these rules in detail so you can learn English grammar and feel confident using ‘cannot’ ‘can not’ and ‘can’t’.
Please subscribe for more videos to help you learn English and sound like a native English speaker! \r
\r
Let’s Connect: \r
\r
Facebook Page: https://www.facebook.com/JForrestEnglish \r
Twitter: https://twitter.com/JForrestEnglish\r
LinkedIn: https://www.linkedin.com/in/jenniferforrest\r
Website: http://www.jforrestenglish.com/ \r
\r
Free Guide – Speak English Fluently \u0026 Confidently in 6 Easy Steps. Download Now: \r
https://courses.jforrestenglish.com/freeguidespeakenglishfluentlyandconfidentlyin6easysteps/

Cannot, Can Not, Can't  - Learn English Grammar

Rolling Stones – Angie (HQ)


Rolling Stones, Angie, Angie
When will those clouds all disappear?
Angie, Angie
Where will it lead us from here?
With no lovin’ in our souls and no money in our coats
You can’t say we’re satisfied
But Angie, Angie
You can’t say we never tried
Angie, you’re beautiful
But I hate that sadness in your eyes
Angie, I still love you baby
Remember all those nights we cried
All the dreams we held so close
Seemed to all go up in smoke
Let me whisper in your ear
Angie, Angie
Where will it lead us from here? Yeah
All the dreams we held so close
Seemed to all go up in smoke
Hate that sadness in your eyes
But Angie, I still love you baby
Everywhere I look I see your eyes
There ain’t a woman that comes close to you
Come on baby dry your eyes
But Angie, Angie
Ain’t it good to be alive
Angie, Angie, you can’t say we never tried.

Rolling Stones - Angie (HQ)

นอกจากการดูบทความนี้แล้ว คุณยังสามารถดูข้อมูลที่เป็นประโยชน์อื่นๆ อีกมากมายที่เราให้ไว้ที่นี่: ดูวิธีอื่นๆMAKE MONEY ONLINE

ขอบคุณที่รับชมกระทู้ครับ can not ย่อ

Leave a Reply

Your email address will not be published. Required fields are marked *